大家好我正在使用此代码将文本附加到txt文件中。任何人都可以指导我如何为此案例添加换行符
fOut = new FileOutputStream(new File(myFilePath + BlueFreeConstants.logFileName), true);
osw = new OutputStreamWriter(fOut);
osw.append("<< " + values + " >>");
osw.flush();
osw.close();
fOut.close();
答案 0 :(得分:10)
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();
答案 1 :(得分:2)
osw.append('\n')
。这就是你要找的东西吗?
答案 2 :(得分:2)
osw.append("<<"+values+">>\n");
答案 3 :(得分:1)
这是我创建多行文本文件的代码:
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) {}