Writing at the end of a file via opencsv

前端 未结 4 680
离开以前
离开以前 2020-12-20 11:58

I\'m using opencsv and want to write to a .csv file through multiple sessions. However every time I start a new CSVWriter the old file gets erased. Can I change

4条回答
  •  悲哀的现实
    2020-12-20 12:51

    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) 
    

提交回复
热议问题