从Java中读取缺少拆分的csv文件

时间:2017-01-25 23:07:33

标签: java bufferedreader readfile stringtokenizer

我想用BufferedReader读取csv文件并用StringTokenizer拆分。但是文件中有一行包含这一行:

IDE,12,办公,, 3208.83,0.18,577.5,4876

这里也是我的阅读方法;

public void readFromCSV(){  
    try {
        File file = new File(myFile);
        br = new BufferedReader(new FileReader(file));
        String line = null;
        while((line = br.readLine()) != null) {
            st1 = new StringTokenizer(line,"\n");
            while(st1.hasMoreTokens()) {
                oneLineList = new ArrayList<>();
                st2 = new StringTokenizer(st1.nextToken(),",");
                for(int i = 0; i < 8; i++) {
                    oneLineList.add(st2.nextToken());
                }
                dataList.add(counter,oneLineList);
            }
            counter++;
        }
        br.close();
    }catch(IOException ex) {
        ex.printStackTrace();
    }
}

在for语句中,每行有8个字段,dataList是二维数组列表。

由于一行包含连续昏迷,我无法读取整个数据,我该如何解决此问题?

0 个答案:

没有答案