I am using opencsv to append Java beans to a csv file. I'm using the following code :
public void functionOne(String pathToFile, List<Bookings> bookings){
FileWriter writer = new FileWriter(pathToFile, true);
StatefulBeanToCsvBuilder<Bookings> builder=
new StatefulBeanToCsvBuilder(writer);
StatefulBeanToCsv beanWriter = builder.build();
beanWriter.write(bookings);
writer.close();
}
This method will be called multiple times in my workflow ( hence I want the append flag to be true ). Things are getting appended to csv, however, for each call, the headers ( which are properties of the objects ) are getting repeated as well which is an issue. Any suggestions?
For reference, the csv looks like this :
property1 property2 property3
value1.1 value1.2 value1.3
property1 property2 property3
value2.1 value2.2 value2.3
Expected csv :
property1 property2 property3
value1.1 value1.2 value1.3
value2.1 value2.2 value2.3