-1

I want to read a huge data file (csv format) containing rows and columns. I want to read and process individual columns in order. Which method is more efficient in terms of speed and memory utilization? Shall I use CSVReader or Random Access File feature of Java? Please help. Thanks

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Kaur
  • 279
  • 1
  • 6
  • 18
  • 2
    A `CSVReader` and a `RandomAccessFile` are two different things. Note that every buffered reader is faster than the unbuffered `RandomAccessFile` reads. – Thomas Jungblut Mar 08 '13 at 08:13

1 Answers1

3

If performance and efficiency are your utmost concern, use memory mapped files and NIO and write your own CSV parser.

But most often, this is just a waste of your time. So I suggest that you first try CSVReader and only if you find out that this doesn't work for you, you write your own CSV parser.

Also note that a BufferedReader will usually be faster than RandomAccessFile.

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 1
    +1 - for the point about not wasting your time on performance. It is only worth doing that if you have clear evidence that 1) your application is too slow and 2) reading the file is what is taking most of the time. – Stephen C Mar 08 '13 at 08:27
  • Thanks all for the answer! I will use CSVReader for the time being. As so much other things to code for. – Kaur Mar 08 '13 at 10:46