开发者

reading CSV through JAVA [duplicate]

This question already has answers here: Closed 11 years ago.

Can anyone tell whats the best way of reading a CSV file. The file I am trying to read is nearly 23 MB so it's a taking a lot of time to read the lines through buffered reader:

BufferedReader CSVFile = new BufferedReader(new FileReader("HostSystems.csv"));
String dataRow = CSVFile.readLine(); 
while (dataRow != null){   
    String[] dataArray = dataRow.split(",");  
    for (String item:dataArray) {       
        System.out.print(item + "\t");   
    }            

    System.out.println(); // Print the data line.   
    dataRow = CSVFile.readLine(); 
}

Is ther开发者_运维问答e another efficient way?


You can use opencsv or JSefa (to convert it into xml).


If you want to do not run out of memory and go fast, you need to go down to java.nio. There are plenty questions in here that might help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜