wiley_pastebin

file writing 1

Mar 15th, 2019
2,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. public void writeToFile(String file, List<String> lines){
  2.  try {
  3.  BufferedWriter bw = null;
  4.  try{
  5.   bw = new BufferedWriter(new FileWriter(file));
  6.   for(int i = 0; i < lines.size(); i++){ 
  7.    bw.write(lines.get(i));
  8.    bw.newLine();
  9.   }
  10.  } catch (IOException e) {
  11.   // exception writing to file...
  12.  } finally {
  13.   if(bw != null) {
  14.    bw.close();
  15.  }
  16.  }
  17.  } catch(IOException e) {
  18.   // if close throws an exception...
  19.  }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment