没有System.getProperty(" line.separator")获取换行符? [英] Getting the new line character without System.getProperty("line.separator")?
问题描述
我想创建一个文本文件,而不是加载它没有任何换行符或空格(这是一个简单的RPG)。所以我想测试所有3个主要的操作系统行分隔符,而不是当前的操作系统(s?)。我知道我可以使用System.getProperty(line.separator)获得当前的一个,但是我怎样才能获得Linux,Mac和Windows行分隔符,并将它们转换为Java的字符串?
编辑:我需要这些单个字符表示,因为某些原因\ n不起作用(是的,我在Windows上)。
(Linux和MacOS X),
\\ \\ r
(MacOS 9及更早版本)和\r\\\
(Windows)。 只需对它们进行硬编码 - 它们不会改变! : - )
编辑: \r\\\
- 这是两个字符。
没有单个字符表示
I want to create a text file, than load it up without any newlines or spaces (This is for a simple RPG). So I want to test for all 3 major OS line separators, and than the current OS'(s?) one. I know I can get the current one using System.getProperty("line.separator"), but how can I get Linux, Mac, and Windows line separators and turn them into a string for Java?
Edit: I need a single character representation of these, because for some reason "\n" doesn't work (Yes I'm on windows).
They are "\n"
(Linux and MacOS X), "\r"
(MacOS 9 and older) and "\r\n"
(Windows).
Just hard-code them - they're not going to change! :-)
Edit: There's no "single character representation" of "\r\n"
- it's two characters.
这篇关于没有System.getProperty(" line.separator")获取换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!