Dear JavaFans,

I notice that if you use FileOutputStream and FileWriter to write a string into a textfile (.txt) , the Java i/o implementation doesn't seems to recognize the syntax \n which is the newline function. Anyone facing the same problem? The output text file will simple display all strings in one straight flow without a leaving lines.

8 Years
Discussion Span
Last Post by rimorin

How are you determining that it "doesn't recognise \n"? If you are "checking" the file with Notepad, it is that notepad "doesn't recognise \n", try checking with wordpad (assuming you're on windows, and on MAC the "newline" character is "\r" on Windows it is "\r\n").

You shouldn't be using "\n" anyway, you should be using System.getProperty("line.separator"); .

But, I can guarantee that it is writing everything you tell it to write. It might not write the last x bytes, though, if you do not flush and/or close it properly.


Oh i see ...
Try it and it works.. My mistake ..
Never knew that Notepad can't read \n
I'll try using System.getProperty("line.separator") then ..
Thanks masijade

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.