aftab
aftab

Reputation: 1141

Add Line Break in text file android

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();

Upvotes: 4

Views: 13297

Answers (4)

Vinil Chandran
Vinil Chandran

Reputation: 51

This is my code to create a multiline text file:

FileOutputStream fos=null;
    OutputStreamWriter osw;
    try {
    fos = openFileOutput("login.txt",Context.MODE_PRIVATE);
    fos.write(("Line One").getBytes());
    osw = new OutputStreamWriter(fos);
    osw.append("\r\n");
    osw.append("Line Two");
    osw.flush();
    osw.close();
    fos.flush();
    fos.close();
} catch (Exception e) {}

Upvotes: 1

confucius
confucius

Reputation: 13327

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();

Upvotes: 13

user4o01
user4o01

Reputation: 2698

osw.append("<<"+values+">>\n");

Upvotes: 2

Mxyk
Mxyk

Reputation: 10698

osw.append('\n'). Is that what you're looking for?

Upvotes: 2

Related Questions