Writing at the end of a file via opencsv

前端 未结 4 683
离开以前
离开以前 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 doesn't seem possible to append to a file in opencsv (from an initial look, it looks rather simple), but if you're not restricted to opencsv you can try JExcel. To append to a file in JExcel you essentially need to create a copy then work off that, and overwrite the original. That could be similar in OpenCSV.

    Edit: It seems like your only real option is to try out JExcel or read the entire file into a list, append to it, and write that out. If this is too heavy on memory, keep the stream open, read in chunks, write out chunks, then write out your appended chunk.

提交回复
热议问题