Difference between System.getProperty(“line.separator”); and “\\n” ?

北城以北 提交于 2019-11-29 03:33:36

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.

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

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

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

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

«\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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!