reading CSV through JAVA [duplicate]
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.
精彩评论