使用OpenCSV读取CSV时遇Schr""解析异常的解决方法
OpenCSV读取CSV文件解析异常问题
- 使用OpenCSV读取CSV文件时,遇到包含
Schr""的行,阅读器会错误判断字段结束位置,导致解析失败,其余行可正常读取。 parseInteger是用于调试的自定义函数,尝试多种方法仍未解决问题。
问题行示例
CSV行中存在类似Schr""的双引号转义内容,比如某字段内容为"Schr""dinger"这类格式,引发字段边界识别错误。
相关代码
while ((line = reader.readNext()) != null) { int id = parseInteger(line.length > 0 ? line[0] : null,0); String title = line.length > 1 ? line[1] : null; String abstractText = line.length > 2 ? line[2] : null; int maths = parseInteger(line.length > 3 ? line[3] : null, 0); int physics = parseInteger(line.length > 4 ? line[4] : null, 0); int compsc = parseInteger(line.length > 5 ? line[5] : null, 0); int stats = parseInteger(line.length > 6 ? line[6] : null, 0); int quantbio = parseInteger(line.length > 7 ? line[7] : null, 0); int quantfin = parseInteger(line.length > 8 ? line[8] : null, 0); articles.add(new Article(title, id, abstractText, maths, physics, compsc, stats, quantbio, quantfin)); }
内容的提问来源于stack exchange,提问作者Nathan Alamu
相关产品推荐
相关产品推荐

