简体   繁体   中英

CSVPrinter new line character

I used com.Ostermiller.util.CSVPrinter to print report csv file.

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, 新队

Could someone please advise me how to add new line character?

Thanks, Sean

writeln() stands for "write line".

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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