How to Write a File Line by Line in Java?
This post summarizes the classes that can be used to write a file. 1. FileOutputStream public static void writeFile1() throws IOException { File fout = new File("out.txt"); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); for (int i = 0; i < 10; i++) { bw.write("something"); bw.newLine(); } bw.close(); … Read more