Getting the new line character without System.getProperty(“line.separator”)?

ⅰ亾dé卋堺 提交于 2019-12-11 01:17:17

问题


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).


回答1:


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.




回答2:


Java 7 now has a System.lineSeparator() method.

See Java: How do I get a platform independent new line character?




回答3:


there's no "getter" for these, you just need to copy the strings off the internet into your own constants.



来源:https://stackoverflow.com/questions/3963582/getting-the-new-line-character-without-system-getpropertyline-separator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!