JDK
try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)))) {
writer.println("Append text using JDK only.");
}
Guava
CharSink sink = Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND);
sink.writeLines(singletonList("Append text using Guava."));
Apache Commons IO
FileUtils.writeLines(file, singletonList("Append text using Commons IO."), true);
Gist
https://gist.github.com/gordianyuan/3b9d3411c7f196b11939f508d90f2b78
网友评论