EDIT: I've tried overriding the method as proposed, but it adds a white line
I'm using OpenCSV to read/write from a CSV file, and I need to append a new row of my object "Crime" when a user adds another one.
Until now, I've only found this way of writing in all tutorials:
Writer writer = new FileWriter(path.toString());
StatefulBeanToCsv sbc = new StatefulBeanToCsvBuilder(writer)
.withSeparator(CSVWriter.DEFAULT_SEPARATOR)
.build();
List<CsvBean> list = new ArrayList<>();
list.add(new WriteExampleBean("Test1", "sfdsf", "fdfd"));
list.add(new WriteExampleBean("Test2", "ipso", "facto"));
sbc.write(list);
writer.close();
The problem is that before adding the new row, it also adds the header, so my file becomes:
zipCode,totPopulation,medianAge,totMales,totFemales,totHouseholds,avgHouseholdSize,
91371,1,73.5,0,1,1,1,
90001,57110,26.6,28468,28642,12971,4.4,
90002,51223,25.5,24876,26347,11731,4.36,
90003,66266,26.3,32631,33635,15642,4.22,
zipCode,totPopulation,medianAge,totMales,totFemales,totHouseholds,avgHouseholdSize,
100,100,100,100,100,100,100
where the line with all "100" values is the one I add. How can I prevent to add the header before the line every time I want to add a row or multiple rows?