Search code examples
javafilecsvsupercsv

How to append data to File using SuperCSV using CsvListWriter


I have a method to write data to a file.

public void writeCSFFileData(List<String> fileData){
    try {
        CsvListWriter csvWriter = new CsvListWriter(new FileWriter("/path/file.csv"), CsvPreference.STANDARD_PREFERENCE);
        csvWriter.write(fileData);
        csvWriter.close();

    } catch (Exception e) {
        SimpleLogger.getInstance().writeError(e);
    }

The above method is called several times to write to a file. But, each time the file is not appended instead it is overwritten.

Thanks in advance.


Solution

  • I found the solution myself, I just need to add true in FileWriter to append the data.

    Ex: new FileWriter("/path/file.csv",true)