osiegmar / FastCSV

CSV library for Java that is fast, RFC-compliant and dependency-free.
https://fastcsv.org/
MIT License
551 stars 93 forks source link

OutputStreamWriter is always run with WRITE operation #24

Closed danielGz closed 3 years ago

danielGz commented 6 years ago

OutputStreamWriter is always run with WRITE option so the file content gets replaced everytime.

mithutokder commented 4 years ago

Any fix for this? CsvWriter should provide option for amend and create new file

osiegmar commented 4 years ago

I will consider this as part of an API overhaul. But for now, you could simply to this to append to a file:

File file = new File("/tmp/foo");

CsvWriter csvWriter = new CsvWriter();
try (CsvAppender append = csvWriter.append(new FileWriter(file, true))) {
    append.appendLine("a", "b");
}
mithutokder commented 4 years ago

Thanks for the reply & the workaround. But, the name method name 'append' is bit confusing. Any plan to work on it? The writer should provide method for creating new file & appending to existing file.

michael-martinez commented 4 years ago

+1 the method name is really confusing could you please rename the append method and provide a proper append method with the workaround you provided on master branch? I guess a lot of API users will lose some time on this.

osiegmar commented 4 years ago

Will be handled in 2.0 - see https://github.com/osiegmar/FastCSV/blob/05046c0a161d946224f9c7c1cf96fb47bb242bc0/src/main/java/de/siegmar/fastcsv/writer/CsvWriterBuilder.java#L129