首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java中写到文件东西,如何已追加的形式存到文本文件中去啊

2012-01-11 
java中写到文件东西,怎么已追加的形式存到文本文件中去啊?java中写到文件东西,怎么已追加的形式存到文本文

java中写到文件东西,怎么已追加的形式存到文本文件中去啊?
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));
}

热点排行