Skip to content

7 Exporting data to a CSV file

Dan Geabunea edited this page Apr 2, 2015 · 2 revisions

There are times when we also want to write data to CSV. Luckily, the EasyCsv library can help with this task as well. Each CsvDocument object can be exported to a file. You can use 2 approaches:

Get string representation of CsvDocument and save manually later

CsvDocument document = ...  
String csvContent = document.toString();
//manually save a file with the csvContent
...

Save directly to file

CsvDocument document = ...
String outputPath "\home\user\downloads";
boolean saveResult = CsvDocument.tryWriteToFile(document , outputPath);
if(saveResult){
    //save successful
}
else{
    //save not successful
}
...