Carriage returns/line breaks with \n in strings in Android

Maxim Zaslavsky picture Maxim Zaslavsky · Jan 1, 2012 · Viewed 27k times · Source

I'm writing an Android app where I'm writing a file to disk with one data value per line. Later, such files can be read back into the app, and this simple data format is deserialized back into an array. At the moment, I'm delineating data values/lines in the serialization and deserialization code with \n.

How does Android handle carriage returns and such line breaks? Can I use \n safely in this context?

Answer

Rajdeep Dua picture Rajdeep Dua · Jan 1, 2012

Its better to use

String lineSep = System.getProperty("line.separator");