java files

Java write to file line by line

public void write(String str) throws IOException
Writes a string.
Parameters:
str – String to be written
Throws:
IOException – If an I/O error occurs

package com.candidjava.file;

import java.io.File;
import java.io.FileWriter;

public class JavaFileWriteLineByLine {
  public static void main(String[] args) throws Exception 
     {
        FileWriter fw=new FileWriter("F:/Files/writeLine.txt"); 
        fw.write("Welcome to Candid java\n");
        fw.write("Java FileWriter class is used to write character-oriented data to a file.");
        fw.flush();
        fw.close();
        System.out.println("File write completed");
     }

}