You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 07:36:14