There is an overload for FileUtils.writelines () that takes a parameter to add.
public static void writeLines(File file, Collection<?> lines, boolean append) throws IOException
file - file to write to
lines - lines for writing, zero records create empty lines
append - if true, then the lines will be added to the end of the file, but will not be overwritten
Option 1:
FileUtils.writeLine(file_to_write, "line 1"); FileUtils.writeLine(file_to_write, "line 2");
file_to_write will only contain
line 2
As soon as the first record in the same file overwrites the file several times.
Case 2:
FileUtils.writeLine(file_to_write, "line 1"); FileUtils.writeLine(file_to_write, "line 2", true);
file_to_write will contain
line 1 line 2
A second call will be added to the same file.
See java official documentation for more details. https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#writeLines(java.io.File , java.util.Collection, boolean)
Kris
source share