Java Program to Write in a File Line by Line

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

//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