Carriage returns/line breaks with \n in strings in Android
Yes, the line separator under Windows is \r\n
(CR+LF), on Mac \r
and on Linux (Android) \n
. Java has a clever reader which returns the line without separator, and a println which uses the platform setting System.getProperty("line.separator")
.
1 - like the two people before me I say, System.getProperty("line.separator")
is your friend.
2 - As android is based on linux it is most likely that the line.separator
property is in fact \n
3 - When reading or writing your files use buffered reader and writer an respectively their methods readLine and newLine. You should not have any trouble dealing with input/output files from/for other platforms.
Its better to use
String lineSep = System.getProperty("line.separator");