Writing at the end of a file via opencsv

This is possible with OpenCSV, please have a look at the below example to append resultset to the existing csv file.

CSVWriter writer = new CSVWriter(new FileWriter(fileName.concat(".csv"), true), ',');

writer.writeAll(resultSet, true);

The second parameter to the FileWriter constructor is bool to open a file in append mode.

FileWriter(String fileName, boolean append) 

There's an option in the FileWriter instead of the CSVWriter to append at the end of the file.

This code makes it work:

mFileWriter = new FileWriter(file_path, true);
mCsvWriter = new CSVWriter(mFileWriter);

Tags:

Java

Csv

Opencsv