System.getProperty(" line.separator");之间的区别;和“\ n” ? [英] Difference between System.getProperty("line.separator"); and "\n" ?

查看:132
本文介绍了System.getProperty(" line.separator");之间的区别;和“\ 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆