wiley_pastebin icon

file writing 1

wiley_pastebin | PRO | 03/15/19 03:18:54 PM UTC | 0 ⭐ | 2415 👁️ | Never ⏰ | []
Java |

450 B

|

None

|

0 👍

/

0 👎

public void writeToFile(String file, List<String> lines){
 try { 
 BufferedWriter bw = null; 
 try{ 
  bw = new BufferedWriter(new FileWriter(file)); 
  for(int i = 0; i < lines.size(); i++){ 
   bw.write(lines.get(i)); 
   bw.newLine(); 
  } 
 } catch (IOException e) { 
  // exception writing to file... 
 } finally { 
  if(bw != null) { 
   bw.close(); 
 }
 } 
 } catch(IOException e) { 
  // if close throws an exception...
 } 
}

Comments