wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes line.separator vs println() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "line.separator vs println()" Watch "line.separator vs println()" New topic
Author

line.separator vs println()

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1732
    
  12



Does this buy you something that just calling println() won't get you?


Thanks,
Janeice


When you do things right, people won't be sure you've done anything at all.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1836
    
    7

Nope. the println() method of the PrintStream class forwards to the newLine() method of BufferedWriter, which retrieves the value of the line.separator system property.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
It will allow you to inspect the line.separator String, see how many characters it contains, etc. If I remember correctly it is (char)0xa no *nix and newer Macs, (char)0xd(char)0xa on DOS/Windows and (char)0xd on older Macs.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Campbell Ritchie wrote:If I remember correctly it is (char)0xa no *nix and newer Macs, (char)0xd(char)0xa on DOS/Windows and (char)0xd on older Macs.

Or simply \n on *nix (Unix, Linux, etc) and newer Macs, \r\n on DOS/Windows and \r on older Macs. Yes they are the same characters, but aren't \r and \n easier to read than (char)0xd and (char)0xa, or even (char)13 and (char)10?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1732
    
  12

Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Yes, but people might not know that \r is (char)0xd.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Would they need to? And if so, I have www.asciitable.com for that information
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: line.separator vs println()