简体   繁体   中英

Writing new lines to a text document in Android fails to add new lines

I am attempting to write some text to a text file and add a new line to it. The only thing that shows up is the "\\n".

So my text file looks like this

Some message.\nFrom someone\nAbout Something\nEtc etc etc\n

There are not line breaks.

Here is my code to append my text file. What am I doing wrong?

String logreport = "SOME TEXT;
try {
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(mContext.openFileOutput(LOG_FILE_NAME, mContext.MODE_APPEND));
    outputStreamWriter.append(logreport);
    outputStreamWriter.append("\n\r");
    outputStreamWriter.close();
} catch (IOException e) {
    Log.e(TAG, "File write failed: " + e.toString());
}

Try to only append the \\n

Like: append("\\n");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM