【发布时间】: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);线。
【问题讨论】:
-
错误是什么?