0

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 there another efficient way?

LOZ
  • 1,169
  • 2
  • 16
  • 43
Monojeet Nayak
  • 721
  • 1
  • 7
  • 13

2 Answers2

1

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

Tobias
  • 9,170
  • 3
  • 24
  • 30
0

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.

ssedano
  • 8,322
  • 9
  • 60
  • 98