我想知道当我在记事本中打开文件时。我看到一条没有任何回车/换行的连续行。
我做了一个java程序来读取文件。当我使用 \n
或 System.getProperty("line.separator");
从文件中拆分数据时。我看到很多行。
我在十六进制编辑器中发现该文件的换行符为“0A”(在 UNIX 中使用),它在记事本中显示为矩形。
嗯,我的问题是,如果它没有“0D”和“OA”(在 Windows 中用于回车和换行)。我的 java 程序如何将数据拆分成行?它不应该拆分它。
有人知道吗?
最佳答案
Java 在内部使用 Unicode。
The Unicode standard defines a large number of characters that conforming applications should recognize as line terminators:[3]
LF: Line Feed, U+000A
VT: Vertical Tab, U+000B
FF: Form Feed, U+000C
CR: Carriage Return, U+000D
CR+LF: CR (U+000D) followed by LF (U+000A)
NEL: Next Line, U+0085
LS: Line Separator, U+2028
PS: Paragraph Separator, U+2029
( http://en.wikipedia.org/wiki/Newline )
这就是为什么它将 \n
解释为换行符。
关于java - 在java中读取换行字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11465749/