Difference between System.getProperty(“line.separa

2020-02-09 06:42发布

While developing GUI with Java FX , I seem to get different results with System.getProperty("line.separator"); and "\n" during writing to a file or getting data from internet. What basically is the difference ?

4条回答
Juvenile、少年°
2楼-- · 2020-02-09 07:27

on the Windows platform, System.getProperty("line.separator") is "\r\n", "\n" (Linux and MacOS X), "\r" (MacOS 9 and older)

查看更多
看我几分像从前
3楼-- · 2020-02-09 07:29

«\n» is the line separator for most operating systems such as Linux/Unix. To ensure the compatibility with any operating system, query this value with System.getproperty

查看更多
Deceive 欺骗
4楼-- · 2020-02-09 07:36

System.getProperty("line.separator") is platform dependent:

  • "\n" on UNIX style machines
  • "\r\n" on Windows machines

Whereas "\n" is only "\n".

查看更多
趁早两清
5楼-- · 2020-02-09 07:41

System.getProperty("line.separator") returns the OS dependent line separator.

On Windows it returns "\r\n", on Unix "\n". So if you want to generate a file with line endings for the current operating systems use System.getProperty("line.separator") or write using a PrintWriter.

查看更多
登录 后发表回答