• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CR[carrige return] in text file for new line

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic