我正在使用Commons CSV解析与电视节目相关的CSV内容。其中一个节目有一个节目名称,其中包含双引号;使用Commons CSV进行CSV解析 - 引起IOException的引号引用
116,6,2,29 09月10 “” JJ “(60分钟)”, “http://www.tvmaze.com/episodes/4855/criminal-minds-6x02-jj”
的showname是 “JJ”(60分钟),这是已经在双引号。这是抛出一个IOException java.io.IOException:(第1行)封装的令牌和分隔符之间的无效字符。
ArrayList<String> allElements = new ArrayList<String>();
CSVFormat csvFormat = CSVFormat.DEFAULT;
CSVParser csvFileParser = new CSVParser(new StringReader(line), csvFormat);
List<CSVRecord> csvRecords = null;
csvRecords = csvFileParser.getRecords();
for (CSVRecord record : csvRecords) {
int length = record.size();
for (int x = 0; x < length; x++) {
allElements.add(record.get(x));
}
}
csvFileParser.close();
return allElements;
CSVFormat.DEFAULT已经设置withQuote( '' “)
我认为这个CSV格式不正确的 ”“ JJ”(60分钟) “应为 ”“, ”JJ“”( 60分钟)“ - 但有没有办法让公共CSV来处理这个问题,或者我需要手动修复这个条目吗?
其他信息:其他显示名称在CSV条目中包含空格和逗号,引用
withQuote(““”)已经默认设置不幸的是,空间是合法入境和内遏制。在CSV中的各种其他行在这种方式我不能把它作为一个引号字符 – mhollander38
@ mhollander38空间仍然是我的格式合法,我会添加一个例子和输出 – SHG