There are new line characters inside the String as you expected. See this modified snippet.
Post by:Rodrigo Tomita
, Ranch Hand
Unless you are writing your String to a text file and you are a Windows user. Then the new line character depends on your OS (\n for Unix, \r\n for Windows and \r for old Macs) and you should use:
[ July 10, 2008: Message edited by: Rodrigo Tomita ]
Post by:Higgledy Smith
, Ranch Hand
This is an old thread, but I don't understand why Shiaber Shaam is not getting the expected new line in his output. Can anyone explain this? Thanks.
Post by:James Byrer
As Rodrigo said above, each OS has it's own "New line" character. You should use System.getProperty("line.separator") to automatically get the appropriate line separator. The "\n" he is using probably isn't working because he is running his app. on a Windows system.
Post by:Lukasz Jarocki
I have similar problem.
I am trying to read some text from .ini file and display it on JOptionPane confirm dialog. Here is the text in .ini file:
I supposed that each part of text will be placed in another line. But I was wrong. Whole string is in single line.
Surprisingly, I receive the same effect when I put string on stdout by System.out.println().
Here is the code:
Of course "sometext" appears in new line on console. How can I fix it?
There is something wrong with that file you are reading, having \r\n in places and \n elsewhere. It looks as if it has been half written in Windows® and hal in Linux.
String.format("This is a String%n%s is brilliant%n", name); Or similar
Your \n worked on a JOptionPane dialogue on my Linux box.
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user