可以阿帕奇FileUtils.writeLines()提出,要附加到文件(如果存在) [英] Can apache FileUtils.writeLines() be made to append to a file if it exists
问题描述
在公共<一个href=\"http://commons.apache.org/io/api-release/index.html?org/apache/commons/io/FileUtils.html\">FileUtils看pretty爽了,我简直不敢相信,他们不能进行追加到一个文件中。
The commons FileUtils look pretty cool, and I can't believe that they cannot be made to append to a file.
File file = new File(path);
FileUtils.writeLines(file, printStats(new DateTime(), headerRequired));
以上只是替换文件的内容,每一次,我只想保持标记这个东西最终只是因为这code一样。
The above just replaces the contents of the file each time, and I would just like to keep tagging this stuff to end just as this code does.
fw = new FileWriter(file, true);
try{
for(String line : printStats(new DateTime(), headerRequired)){
fw.write(line + "\n");
}
}
finally{
fw.close();
}
我搜索的Javadoc但一无所获!我缺少什么?
I've searched the javadoc but found nothing! What am I missing?
推荐答案
您可以使用<一个href=\"http://commons.apache.org/io/api-release/org/apache/commons/io/IOUtils.html#writeLines%28java.util.Collection,%20java.lang.String,%20java.io.Writer%29\">IOUtils.writeLines(),它收到一个Writer对象,你可以初始化就像你第二个例子。
You can use IOUtils.writeLines(), it receives a Writer object which you can initialize like in your second example.
这篇关于可以阿帕奇FileUtils.writeLines()提出,要附加到文件(如果存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!