This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is There Any Difference Between ....." Watch "Is There Any Difference Between ....." New topic
Author

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
/n
?
Blake Minghelli
Ranch Hand

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

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
Wanderer
Sheriff

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Is There Any Difference Between .....