In this tutorial, you will learn how to Write in a File Line by Line in java. To understand it better, you may want to check the following first:
Java Program to Write in a File Line by Line
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | //write in a file line by line import java.io.*; public class FileWrite { public static void main(String[] args) throws IOException { File f = new File("javaCode.txt"); FileWriter fw = new FileWriter(f); fw.write("Welcome to Simple2Code. \n"); fw.write("Start the Tutorial"); fw.flush(); fw.close(); System.out.println("Done..Check javaCode.txt"); } } |
Output:
Done..Check javaCode.txt
javaCode.txt
Welcome to Simple2Code.
Start the Tutorial