[英]System.getProperty(“line.separator”) Vs “\n” for Android
[英]Difference between System.getProperty(“line.separator”); and “\n”?
在使用 Java FX 开发 GUI 时,我似乎使用System.getProperty("line.separator");
得到了不同的结果System.getProperty("line.separator");
和"\\n"
在写入文件或从互联网获取数据期间。 基本上有什么区别?
System.getProperty("line.separator")
返回操作系统相关的行分隔符。
在 Windows 上它返回"\\r\\n"
,在 Unix 上返回"\\n"
。 因此,如果要为当前操作系统生成带有行结尾的文件,请使用System.getProperty("line.separator")
或使用PrintWriter
编写。
在 Windows 平台上, System.getProperty("line.separator") 为 "\\r\\n"、"\\n"(Linux 和 MacOS X)、"\\r"(MacOS 9 及更早版本)
System.getProperty("line.separator")
是平台相关的:
而“\\n”只是“\\n”。
«\\n» 是大多数操作系统(如 Linux/Unix)的行分隔符。 为确保与任何操作系统兼容,请使用 System.getproperty 查询此值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.