| Author |
CR[carrige return] in text file for new line
|
Eung maeng
Ranch Hand
Joined: Feb 10, 2002
Posts: 68
|
|
Please explain to me how to solve. I can create a text file for multiple lines when i run java on window. However, when execute a java by Qshell based on Iseries box, the text file created only one line with carrige return between lines. However, I can see all lines correct when open wordPad rather than notepad. I can not understand why. e.g FileWriter fw= new FileWriter(file); PrintWriter pw = new PrintWriter(fw); while(... pw.print("ddd"); pw.print("bbb"); pw.print("ccc" +"\n"); or pw.println("ccc"); }end of while please advice me what I need to try. Regards,
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16479
|
|
On Windows systems, Java will use CR-LF (\r\n) at the end of a line by default. On Unix-like systems (including the iSeries) it will just use LF, and I believe that on Mac systems it will use CR. Pretty much every text editor in the world understands that a line can be ended by any of those three combinations of characters. Notepad is one of the tiny minority that doesn't understand that. So the simplest thing to do is to stop using Notepad. Even Microsoft makes a better editor, Notepad. If you are generating text files that people will read with whatever editor they choose, that isn't going to work, of course. But if it's just something you noticed when you were debugging, then forget about it.
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Paul Clapham: ...So the simplest thing to do is to stop using Notepad. Even Microsoft makes a better editor, Notepad...
I think that's Wordpad.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Eung maeng
Ranch Hand
Joined: Feb 10, 2002
Posts: 68
|
|
thanks a lot. I used \r\n. It works for Window and iseries. This forum is very useful for me. Quick respond and get a direction etc cheers,
|
 |
 |
|
|
subject: CR[carrige return] in text file for new line
|
|
|