Reputation: 9
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();
}
}
Upvotes: 0
Views: 72
Reputation: 76
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"));
Upvotes: 0
Reputation: 151
You could enter '\n' at the end of each line. Or write an string consisting of a space to the file.
Upvotes: 2