我看到了一些关于 CSVWriter 写入文件和引号的其他问题。但没有什么比我的问题更具体。
我想打印类似的东西:
abc,def,ghi,"jkl",mno,pqr
当我只是写:
CSVWriter writer = new CSVWriter(new FileWriter(getFullPathToTestFile(), true));
String[] newLine = { "abc","def","ghi","jkl","mno","pqr" };
writer.writeNext(newLine);
打印出来的是:
"abc","def","ghi","jkl","mno","pqr"
所以我尝试了:
CSVWriter writer = new CSVWriter(new FileWriter(getFullPathToTestFile(), true), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
String[] newLine = { "abc","def","ghi","jkl","mno","pqr" };
writer.writeNext(newLine);
这给了我:
abc,def,ghi,jkl,mno,pqr
但我需要 jkl 上的引号。所以我尝试了类似的东西:
CSVWriter writer = new CSVWriter(new FileWriter(getFullPathToTestFile(), true), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
String[] newLine = { "abc","def","ghi","\""+"jkl"+"\"","mno","pqr" };
writer.writeNext(newLine);
这令人惊讶地给了我:
abc,def,ghi,""jkl"",mno,pqr
在这一点上,我没有想法。有人可以帮助我理解这一点,并且任何有关使其正常工作的提示也将不胜感激。