简体   繁体   English

在Android中将新行写入文本文档无法添加新行

[英]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". 唯一显示的是“ \\ 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 尝试仅附加\\n

Like: append("\\n"); 像: append("\\n");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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