问题
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