我正在使用univocity CSV解析器将我的内容导出到CSV文件。 这是我预期的CSV文件输出,
#Comment Section-1
#Comment Section-2
Header-1,Header2,Header3
Data-1,data-2,data-3
但是在将内容导出为CSV文件时,我的格式低于格式,
Header-1,Header2,Header3
#Comment Section-1
#Comment Section-2
Data-1,data-2,data-3
如何将评论部分移至univocity CSV解析器lib的顶部?
答案 0 :(得分:0)
这应该有效:
//let's write to a String to make this easy to test
StringWriter out = new StringWriter();
CsvWriterSettings settings = new CsvWriterSettings();
//set headers
settings.setHeaders("a", "b", "c");
//automatically write headers when the first data row is written
settings.setHeaderWritingEnabled(true);
CsvWriter writer = new CsvWriter(out, settings);
//write comment
writer.commentRow("lalala");
//write data rows
writer.writeRow("1", "3", "6");
writer.writeRow("3", "1", "1");
writer.close();
//print output
System.out.println(out);
产生的输出是:
#lalala
a,b,c
1,3,6
3,1,1
希望这有帮助。