• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newline using System . getProperty("line.separator")  RSS feed

 
Bony Sen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am writing some data into a text file. This data uses System . getProperty("line.separator") to get a new line.
On some machines, instead of getting a new line I'm getting those weird boxes.
Does this problem occur on Unix machines or culd the problem be something else?
 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Different platforms use different newline characters:
wikipedia
If you write a file on one platform and move it to another, it will have the wrong newline character.
 
Bony Sen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this command works on all platforms right? It should work for Windows and Unix.
 
Bony Sen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is deployed on Unix Server. When we access the application on Windows, we don't get the newline. The entire output comes in one line. How can we overcome this problem?
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you specifically want it to work on Windows you may have to use the Windows combination which is "\r\n" I think. Same as I used on a TeleType (TTY) in 1971!
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line separator is there; the problem is with the program you're using to view the text: Windows Notepad. Every other program in the world will accept any of the three most common line separators: "\n" (linefeed only), "\r" (carriage-return only), or "\r\n" (carriage-return + linefeed). But Notepad only recognizes "\r\n", the traditional line separator for DOS/Windows systems. Just use something other than Notepad to view the text, and don't worry about the line separators.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not just Notepad. Visual Basic's TextBox component has the same problem, and therefore all applications that use it and don't have custom coding to replace "invalid" line break characters.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!