[英]android add text line at the beginning of .txt file
我有这个代码
File gpxfile = new File(root, "mesaje.txt");
BufferedWriter bW;
bW = new BufferedWriter(new FileWriter(gpxfile, true));
bW.write(format + " " + message + "\n-----------------------\n");
bW.newLine();
bW.flush();
bW.close();
它会写一个.txt文件,在最后一行之后添加文本。 我想在第一行添加文本,以便它将显示为最新信息。 我怎样才能做到这一点? 谢谢!
读取文件,并将其存储为字符串。 然后,只需添加新的文本,然后添加前一个文件中保存的字符串,即可重写文件。 这里有许多读取文本文件的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.