0

i am using FileWriter object to write some string in file imtiyaz.txt but i also want to use line separator manually by '\n' but i am not able to separate line by '\n' i know that i can resolve this problem by using BufferedWriter but i want to do by using FileWrite and i wnat to know that is it possible or not if it is not possible then why ?

package first; import java.io.*;

public class Example {

    public static void main(String[] args) throws IOException {
    
        FileWriter fw = new FileWriter("imtiyaz.txt");
        fw.write("hellow imtiyaz \n hi how are you ?");
        fw.write('\n');
        fw.write("i think you are revising java concept");

        fw.flush();
        fw.close();
        
    }

}
Imtiyaz
  • 9
  • 2

2 Answers2

2

You could enter '\n' at the end of each line. Or write an string consisting of a space to the file.

Luducrous
  • 86
  • 4
0

This question has already been answered here. But, essentially, you will have to use "line.separator" as your "\n" like so:

fw.write(System.getProperty("line.separator"));
Akash Veerappan
  • 76
  • 1
  • 1
  • 6