[英]Convert Java Object to TSV in java
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 ie ReportMessageStructure public class ReportMessageStructure { 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 ie 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.现在我的要求是将数据写入 TSV 文件。 Could you please suggest me best way to do this.
你能否建议我最好的方法来做到这一点。 I know I can use JAXB if I had to convert into XML.
我知道如果我必须转换为 XML,我可以使用 JAXB。 However need way to convert into TSV.
但是需要转换成 TSV 的方法。 Any tips/suggestion would be great help.
任何提示/建议都会有很大帮助。
Max size the data will produce would be around 700MB from object to TSV从 object 到 TSV,数据将产生的最大大小约为 700MB
You can use CSVPrinter
from Apache Commons CSV library with CSVFormat
equal to TDF
.您可以使用
CSVPrinter
Commons CSV库中的 CSVPrinter ,其中CSVFormat
等于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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.