System.getProperty("line.separator")之间的区别; 和"\n"?

Til*_*ddy 16 java file-handling javafx-8

在使用Java FX开发GUI时,我似乎使用System.getProperty("line.separator")获得了不同的结果; 在写入文件或从互联网上获取数据时写入"\n".基本上有什么区别?

wer*_*ero 30

System.getProperty("line.separator") 返回OS依赖行分隔符.

在Windows上,它"\r\n"在Unix上返回"\n".因此,如果要为当前操作系统生成具有行结尾的文件,请使用System.getProperty("line.separator")或使用PrintWriter.


EL *_*bib 12

在Windows平台上,System.getProperty("line.separator")是"\ r \n","\n"(Linux和MacOS X),"\ r"(MacOS 9及更早版本)


Dan*_*n W 7

System.getProperty("line.separator") 取决于平台:

  • UNIX风格的机器上的"\n"
  • Windows机器上的"\ r \n"

而"\n"只是"\n".