java中写到文件东西,怎么已追加的形式存到文本文件中去啊?
下面是代码, FileWriter FileWriter pw = new FileWriter(
"e:\\aa.txt ");
pw.write(allnumber[f1] + " "
+ allnumber[s2] + " "
+ allnumber[t3] + " "
+ allnumber[f4] + " "
+ allnumber[f5] + " "
+ allnumber[s6] + " ");
pw.close();
在aa。txt文件中,我要出现很多组数据,但是最终,他只显示了一组,应该是在写入的时候都覆盖了前面写入的数据,现在,怎么改下代码,可以让它一追加的形式添加的aa.txt文件中去,那个追加的方法早忘记了,请各位帮下忙.
------解决方案--------------------
FileWriter pw = new FileWriter( "e:\\aa.txt ",true);
------解决方案--------------------
java.io.FileWriter fw = new java.io.FileWriter( "e:\\aa.txt ",true);
看一下API文档嘛...
FileWriter(文件路径,是否追加);
------解决方案--------------------
/**
* Constructs a FileWriter object given a file name with a boolean
* indicating whether or not to append the data written.
*
* @param fileName String The system-dependent filename.
* @param append boolean if <code> true </code> , then data will be written
* to the end of the file rather than the beginning.
* @throws IOException if the named file exists but is a directory rather
* than a regular file, does not exist but cannot be
* created, or cannot be opened for any other reason
*/
public FileWriter(String fileName, boolean append) throws IOException {
super(new FileOutputStream(fileName, append));
}