org.supercsv.exception.SuperCsvException:读取行首的带引号的列时,文件意外结束 [英] org.supercsv.exception.SuperCsvException: unexpected end of file while reading quoted column beginning on line

查看:365
本文介绍了org.supercsv.exception.SuperCsvException:读取行首的带引号的列时,文件意外结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用superCSV阅读器读取csv文件,但遇到以下异常.该文件有80000行.当我删除末行时,仍然会发生异常,因此文件中有些行导致了此问题.我该如何解决?

I'm reading csv files using superCSV reader and got the following exception. the file has 80000 lines. As I remove the end lines the exception still happens so there's some line in file that's causing this problem. how do I fix this?

org.supercsv.exception.SuperCsvException: unexpected end of file while reading quoted column beginning on line 80000 and ending on line 80000
context=null
        at org.supercsv.io.Tokenizer.readColumns(Tokenizer.java:198)
        at org.supercsv.io.AbstractCsvReader.readRow(AbstractCsvReader.java:179)
        at org.supercsv.io.CsvListReader.read(CsvListReader.java:69)
        at csv.filter.CSVFilter.filterFile(CSVFilter.java:400)
        at csv.filter.CSVFilter.filter(CSVFilter.java:369)
        at csv.filter.CSVFilter.main(CSVFilter.java:292)


         ICsvListReader reader = null;
        String[] line=null;
        ListlineList=null;
        try{

            reader = new CsvListReader(new FileReader(inputFile), CsvPreference.STANDARD_PREFERENCE);

            while((lineList=reader.read())!=null){
                line=lineList.toArray(new String[lineList.size()]);

            }
        }catch(Exception exp){
            exp.printStackTrace();
            error=true;
        }

推荐答案

错误消息中显示的行不一定是有问题的行,因为不平衡的报价字符会影响SuperCSV的行检测.

The line shown in the error message is not necessarily the one with the problem, since unbalanced quotechars throw off SuperCSV's line detection.

如果可能,请在电子表格问题中打开csv(例如libreoffice calc),然后搜索(如CTRL-F搜索一样)报价char.

If possible, open the csv in a spreadsheet problem (for instance libreoffice calc) and search (as in CTRL-F search) for the quote char.

即使存在不匹配的情况,Calc通常也可以很好地导入文件,但是如果您进行搜索,您将在某处看到quotechar.然后,检查csv是否已正确转义.如果是这样,请确保SuperCSV知道它.如果不是,请向csv的生产者投诉.

Calc will usually import the file well, even if there is a mismatch but you will see the quotechar somewhere if you search for it. Then check in the csv if it is properly escaped. If it is, make sure SuperCSV knows about it. If it isn't, complain to the producer of the csv.

这篇关于org.supercsv.exception.SuperCsvException:读取行首的带引号的列时,文件意外结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆