I have been searching a lot for the fastest way to read and write again a large files (0.5 – 1 GB) in java with limited memory (about 64MB). Each line in the file represents a record, so I need to get them line by line. The file is a normal text file.
I tried BufferedReader and BufferedWriter but it doesn't seem to be the best option. It takes about 35 seconds to read and write a file of size 0.5 GB, only read write with no processing. I think the bottleneck here is writing as reading alone takes about 10 seconds.
I tried to read array of bytes, but then searching for lines in each array that was read takes more time.
Any suggestions please?
Thanks
Best Solution
I suspect your real problem is that you have limited hardware and what you do is software won't make much difference. If you have plenty of memory and CPU, more advanced tricks can help, but if you are just waiting on your hard drive because the file is not cached, it won't make much difference.
BTW: 500 MB in 10 secs or 50 MB/sec is a typical read speed for a HDD.
Try running the following to see at what point your system is unable to cache the file efficiently.
On a Linux machine with lots of memory.
On a windows machine with lots of memory.