System.getProperty(" line.separator");之间的区别;和“\ n” ? [英] Difference between System.getProperty("line.separator"); and "\n" ?
问题描述
在使用Java FX开发GUI时,我似乎使用System.getProperty(line.separator)获得了不同的结果;写入文件或从互联网获取数据时写入\ nn。基本上有什么区别?
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 ?
推荐答案
System.getProperty(line.separator)
返回OS相关行分隔符。
System.getProperty("line.separator")
returns the OS dependent line separator.
在Windows上,它在Unix 上返回
。因此,如果要为当前操作系统生成包含行结尾的文件,请使用\\\\ n
\\\ System.getProperty(line.separator)
或使用进行写入PrintWriter
。
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
.
这篇关于System.getProperty(" line.separator");之间的区别;和“\ n” ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!