private void writeFile(List<String> lines,File file) throws Exception {
  try (PrintWriter writer=new PrintWriter(new FileOutputStream(file))){
    for (    String line : lines) {
      writer.println(line);
    }
  }
 }

private void writeFile ( List < String > lines , File file ) throws Exception { try ( PrintWriter writer = new PrintWriter ( new FileOutputStream ( file ) ) ) { for ( String line : lines ) { writer . println ( line ) ; } } }
write lines to a file .
