简体   繁体   中英

csvreader remove quotes from string when writing

I'm using csvreader/write to create a csv file but when I try appending or writing to the csv with a String it also adds the double quotes.

import com.csvreader.CsvWriter;

public class CSVFile {
    private static final String defaultHeaders = "Node Name,Node IP,Object Name,DateTime";

    CsvWriter csvOutput = new CsvWriter(new FileWriter(user+currDateTime+".csv", true),',');    

    csvOutput.write(defaultHeaders);    
}

OUTPUT of csv is:

"Node Name,Node IP,Object Name,DateTime"

I need:

Node Name,Node IP,Object Name,DateTime

Did you try the writeRecord method?

private static final String defaultHeaders = {"Node Name", "Node IP", "Object Name", "DateTime"};
CsvWriter csvOutput = new CsvWriter(new FileWriter(user+currDateTime+".csv", true),',');    

csvOutput.writeRecord(defaultHeaders); 

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