Possible Duplicate:
How to append text to an existing file in Java
如何在.txt文件的末尾添加字符串?
最佳答案
来自here
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("checkbook.txt", true));
bw.write("400:08311998:Inprise Corporation:249.95");
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally { // always close the file
if (bw != null) {
try {
bw.close();
} catch (IOException ioe2) {
// just ignore it
}
}
}
FileWriter
代替new OutputStreamWriter(new FileOutputStream(..), ecnoding)
FileWriter
使用默认编码,该默认编码在安装之间会有所不同。关于java - 如何在.txt文件的末尾添加字符串? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3253728/