Popular Feed

Write a array list to text file using JAVA

public void writeFile(List<String> listToWrite,String filePath) {

try { FileWriter myWriter = new FileWriter(filePath); for (String string : listToWrite) { myWriter.write(string); myWriter.write("\r\n"); } myWriter.close(); System.out.println("Successfully wrote to the file."); } catch (IOException e) { System.out.println("An error occurred."); e.printStackTrace(); } }

No comments: