File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Is There Any Difference Between ..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is There Any Difference Between ....." Watch "Is There Any Difference Between ....." New topic

Is There Any Difference Between .....

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Is there any difference between
System.getProperty("line.separator"); and
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Is there any difference between
System.getProperty("line.separator"); and

I think you mean "\n" right?
System.getProperty("line.separator") is more portable because it will return the appropriate new line character for the os that is running the java program.
As an example, BufferedReader.newLine() uses System.getProperty("line.separator") to determine how to write a new line.

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Yes. If you use an OS other than Unix, it's often different. On Windows, line.separator will be "\r\n"; on a Mac, I think it's "\n\r" (or something like that). It's often a good idea to look up the line.separator property in order to use the separator that's appropriate to the system you're on. Or use the println() method in PrintStream or PrintWriter to provide it automatically. However if you're working with an application that communicates across different platforms (e.g. a Unix-based server that provides files that will be used on Windows or Mac machines) then you may need to use a separator which is not the system default. Just something to be aware of.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Is There Any Difference Between .....
It's not a secret anymore!