• 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

Is There Any Difference Between .....

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any difference between
System.getProperty("line.separator"); and
/n
?
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic