Writing at the end of a file via opencsv

前端 未结 4 673
离开以前
离开以前 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:33

    It should be possible:

    FileWriter w = new FileWriter("yourfile.csv")
    CSVWriter writer = new CSVWriter(w, '\t');
    ...
    writer.flush();
    CSVWriter writer2 = new CSVWriter(w, '\t');
    ...
    writer2.flush();
    w.close();
    

    The CSV tool from the H2 database (disclaimer: I wrote it) also supports this.

提交回复
热议问题