• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CR[carrige return] in text file for new line

 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic