有没有人有使用Java中的opencsv来编写csv文件的经验,其中只有一些元素需要双引号?我想要测试的所需输出是创建一个文件:
1,"two",three
但是当我尝试以下代码时
writer = new CSVWriter(new FileWriter("yourfile.csv"), ',',CSVWriter.NO_QUOTE_CHARACTER);
String[] entries = {"1","\"two\"","three"};
writer.writeNext(entries);
writer.close();
发生以下输出
1,""two"",three
思想?
答案 0 :(得分:4)
这些额外引号是OpenCSV
使用的转义字符。您需要使用允许您关闭这些内容的overloaded constructor:
writer = new CSVWriter(new FileWriter("yourfile.csv"), ',',
CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.NO_ESCAPE_CHARACTER);
...
输出:
1,"two",three