我的代码出现错误,我不明白为什么。我正在使用OpenCsv库,并尝试将我的CSV保存到数组中。CSV的列看起来像: Date,Sold,Code,然后是下面的信息,比如: 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 =CSVReader CSVReader(reader);行中。
发布于 2018-04-17 03:10:04
尝试删除SAMPLE_CSV末尾的双反斜杠
更改自:
private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv\\";要这样做:
private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv";https://stackoverflow.com/questions/49863713
复制相似问题