Author Topic: When writing to a file, \n fails me!  (Read 732 times)

When using writeLine on my file, when\n appears as a [] box like that, except it's one character.

Note I only see it when I open notepad.


The character displays as a normal line break when viewed with a browser, I somehow have seen this before, in the JDK source.(this is unimportant info)


In a way it's solved, just write a blank line -slap-


But I still want to know why this happens.
« Last Edit: February 28, 2009, 11:55:39 PM by Kalphiter »

That box is a linebreak character. Not sure why it shows like that when using \n, when it should be using a real linebreak.

I remember reading something about how a line break could be a "Line Feed" control (literally 'print one more line' for a printer), "Carriage Return" ('return printing carriage to left-hand side') or both together - \n is only giving one of these, while .writeLine() is probably doing the other or both, but Notepad displays one as a box since it's the wrong kind according to it. Opening some code files in Notepad will result in every line appearing with a box like that and no newlines at all, I get it with some of Jookia's files e.g. CityRP code, probably to do with his text editor. Internet browsers will usually clean up text to make it look nice for the end user - treating a line feed, carriage return or both together as a single line break.

EDIT: http://en.wikipedia.org/wiki/Newline seems to explain this in detail.
« Last Edit: March 01, 2009, 03:42:53 PM by Space Guy »

Interesting. IGSO is also loaded with these.

You should use \r\n to write a new line in a text document.


Thats just the way it works. Torque writes text documents in ASCII format and in general, ASCII requires a carriage return and a line feed character. Notepad happens to be pretty strict about character encoding so it wont know what to do with a \n but if you open it in wordpad instead it works fine. Most unix-type operating systems tend to use a single \n.