简体   繁体   English

CSVPrinter换行符

[英]CSVPrinter new line character

I used com.Ostermiller.util.CSVPrinter to print report csv file. 我使用com.Ostermiller.util.CSVPrinter打印报告csv文件。

ByteArrayOutputStream csvOut = new ByteArrayOutputStream();
CSVPrinter csvp = new CSVPrinter(csvOut);

for(SiteSector siteSector : siteSectorList){
    siteSectors.append(siteSector.getSector().getName()).append("   Description: ").append(siteSector.getSector().getDescription())
    .append("   Primary: ").append(siteSector.isDefaultSector() ? "Yes" : "No").append("\r\n");}

String[] contents = new String[]{siteCodes.toString(), siteSectors.toString()};

csvp.writeln(contents);

The "\\r\\n" does not work as expected as creating new line as below, “ \\ r \\ n”无法按预期方式创建新行,如下所示, 新队

Could someone please advise me how to add new line character? 有人可以告诉我如何添加换行符吗?

Thanks, Sean 谢谢,肖恩

writeln() stands for "write line". writeln()代表“写行”。

You have to invoke csvp.writeln() for every line that you want to write (from within your for loop) - no need for adding manual line separators. 您必须为要编写的每一行调用csvp.writeln() (从for循环内)-无需添加手动行分隔符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM