Issue
I generate a report where I read data from postgresql and then populate a Java object Below is kind of sample skeleton where I want to show there are many collection object within Main object i.e ReportMessageStructure
public class ReportMessageStructure {
protected MessageHeader messageHeader;
protected MessageDuration messageDuration;
protected ObjectA sampleListA;
protected ObjectB sampleListB;
protected ObjectC smapleListC;
}
Now My requirement is to write data into TSV file . Could you please suggest me best way to do this. I know I can use JAXB if I had to convert into XML. However need way to convert into TSV. Any tips/suggestion would be great help.
Max size the data will produce would be around 700MB from object to TSV
Solution
You can use CSVPrinter
from Apache Commons CSV library with CSVFormat
equal to TDF
.
try (CSVPrinter printer = new CSVPrinter(new FileWriter("csv.txt"), CSVFormat.TDF)) {
printer.printRecord("id", "userName", "firstName", "lastName", "birthday");
printer.printRecord(1, "john73", "John", "Doe", LocalDate.of(1973, 9, 15));
printer.println();
printer.printRecord(2, "mary", "Mary", "Meyer", LocalDate.of(1985, 3, 29));
} catch (IOException ex) {
ex.printStackTrace();
}
Answered By - AlexElin
Answer Checked By - David Marino (JavaFixing Volunteer)