下面的代码是我目前的代码,但是它当时覆盖了csv文件中的任何数据,而不是将其附加到最后.是否有捷径可寻?
public void printCustomerList() throws IOException{
FileWriter pw = new FileWriter("F:\\data.csv");
Iterator s = customerIterator();
if (s.hasNext()==false){
System.out.println("Empty");
}
while(s.hasNext()){
Customer current = (Customer) s.next();
System.out.println(current.toString()+"\n");
pw.append(current.getName());
pw.append(",");
pw.append(current.getAddress());
pw.append("\n");
}
pw.flush();
pw.close();
}
Run Code Online (Sandbox Code Playgroud)
gpr*_*our 33
尝试打开这样的文件
FileWriter pw = new FileWriter("F:\\data.csv",true);
Run Code Online (Sandbox Code Playgroud)
传递true参数以进行追加.
您需要为您的 使用不同的构造函数FileWriter:
FileWriter pw = new FileWriter("F:\\data.csv", true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41970 次 |
| 最近记录: |