【问题标题】:error with csvReader line when using OpenCsv使用 OpenCsv 时 csvReader 行出错
【发布时间】:2018-04-16 18:09:36
【问题描述】:

我的代码出现错误,我不明白为什么。我正在使用 OpenCsv 库并尝试将我的 CSV 保存到一个数组中。 CSV 具有如下所示的列:日期、已售出、代码,然后其下的信息如下:1123、may4、0021;3323;

我的代码是:

 private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv\\";

public static void main(String[] args) throws IOException{


     { 

        try (
            Reader reader = Files.newBufferedReader(Paths.get(SAMPLE_CSV));
            CSVReader csvReader = new CSVReader(reader);
        ) {
            // Reading Records One by One in a String array
            String[] nextRecord;
            while ((nextRecord = csvReader.readNext()) != null) {
                System.out.println("Order num : " + nextRecord[0]);
                System.out.println("SoldToAct : " + nextRecord[1]);
                System.out.println("RequestedDelivery : " + nextRecord[2]);
                System.out.println("BaseCode : " + nextRecord[3]);
                 System.out.println("Option Code : " + nextRecord[4]);
                System.out.println("==========================");
            }
        }

错误在 CSVReader csvReader = new CSVReader(reader);线。

【问题讨论】:

  • 错误是什么?

标签: java csv


【解决方案1】:

尝试删除SAMPLE_CSV 末尾的双反斜杠:

更改自:

private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv\\";

到这里:

private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv";

【讨论】:

  • 它没有工作,仍然在线程“main” java.lang.NoClassDefFoundError: org/apache/commons/lang3/ObjectUtils 错误中得到异常
  • stackoverflow.com/a/46034653/2848676 是否解决了您的 java.lang.NoClassDefFoundError 问题?
  • 如何下载 apache commons lang
猜你喜欢
  • 2022-11-13
  • 2020-10-12
  • 1970-01-01
  • 2021-01-31
  • 1970-01-01
  • 2014-01-24
  • 2021-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多