【问题标题】:java.io.IOException: Un-terminated quoted field at end of CSV linejava.io.IOException:CSV 行末尾未终止的引用字段
【发布时间】:2011-06-25 10:14:58
【问题描述】:

我有一个 CSV 文件(用德语编写),我正在我的代码中解析它。

CSVParser newLineParser = new CSVParser('\n');

        try {

            String[] points = newLineParser.parseLine(csv);
            CSVParser commaParser = new CSVParser();
            int pointsLength = points.length;

            for (int i = 1; i < pointsLength; i++) {

                String[] pointComponents = commaParser.parseLine(points[i]);
            }

        } 
        catch (Exception e) {
            Log.e("Exception", e.getMessage());
        }

我在 parseLine 方法中遇到错误:

java.io.IOException: Un-terminated quoted field at end of CSV line

这个错误的原因可能是什么?

【问题讨论】:

    标签: android parsing csv


    【解决方案1】:

    我从中得到的是,在您的 CSV 文件中,报价已打开但未关闭。

    【讨论】:

      【解决方案2】:

      格式错误的 csv 文件

      在你的循环中做一些打印输出,看看在程序崩溃之前会发生什么。

      【讨论】:

        【解决方案3】:

        如果您使用的是 OpenCSV API,那么这可能是问题所在:

        问题:csv 文件中的一个或多个值有多行。

        修复:改用 commaParser.parseLineMulti(points[i])。

        Source: Http://opencsv.sourceforge.net/apidocs/com/opencsv/CSVParser.html#parseLineMulti(java.lang.String)
        

        【讨论】:

          猜你喜欢
          • 2022-12-15
          • 2018-12-29
          • 2022-01-17
          • 1970-01-01
          • 2018-04-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多