【发布时间】:2015-03-27 07:32:24
【问题描述】:
我可以读取 csv 文件,但是当该行为空白或为空时,它会显示 Arrayindexoutofboundexception。当行为空时如何继续读取文件。
File file = new File("D:\\ms.csv");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines) {
String[] array = line.split(",");
System.out.println(array[0]+","+array[1]);
}
我的 csv 如下所示,中间有空行
sid, name, image
PC-GHF - 10677, Wine, /g/h/ghf_10677.jpg
PC-GHF - 10482, Green, /g/h/ghf_10482.jpg
PC-GHF - 10483, Shaded Cream, /g/h/ghf_10483..jpg
PC-GHF- 10484, White, /g/h/ghf_10484.jpg
【问题讨论】: