Add Line Break in text file android

aftab picture aftab · Jul 18, 2012 · Viewed 12.2k times · Source

Hi All I am using this code to append text in a txt file.anyone can guide me how i can add line break for this case

fOut = new FileOutputStream(new File(myFilePath + BlueFreeConstants.logFileName), true);
osw = new OutputStreamWriter(fOut);
osw.append("<< " + values + " >>");
osw.flush();
osw.close();
fOut.close();

Answer

confucius picture confucius · Jul 18, 2012
String separator = System.getProperty("line.separator");
fOut = new FileOutputStream(new File(myFilePath + BlueFreeConstants.logFileName), true);
osw = new OutputStreamWriter(fOut);
osw.append("<< " + values + " >>");
osw.append(separator); // this will add new line ;
osw.flush();
osw.close();
fOut.close();