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.

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.