-1

I need generate report of some big amount of data into csv file. I want avoid loading all data into memory and flush them all. My preferable way is create csv header and next in sequence write data into csv.

I'm using csv printer of apache csv which can create csv line with some settings. But when I call after every write flush writing is too slow.

Do you have any advice how to solve that task?

Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174

1 Answers1

0

BufferedWriter

Java offers the BufferedWriter class to automatically handle efficient writing to storage. No need for you to call flush. You can set the size of the buffer, but I suggest you start by using the default size.

A convenient way to instantiate such a object is by calling Files.newBufferedWriter.

Base your CSVPrinter object on the BufferedWriter.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154