1

I'm trying to access data (read only) from a very large (>100 GB) ascii coded text file. The file mostly contains coordinates (16 digit float, including decimal point), and some other minor information (names, etc.).

Hence I'm consider using RandomAccessFile to avoid having to load large amount of data into memory. (I could, for instance, cache lines of data into memory to speed it up but let's save that for later and assume time isn't an issue here as long as it's not close to infinity).

Question: may I assume that the seek and read methods would not cause RandomAccessFile to load huge amount of data into memory?

Thank you very much.

Allen Ai
  • 63
  • 1
  • 5
  • If the data is read-only you should use a `DataInputStream` wrapped around a `BufferedInputStream`. You will find this many times as fast, and the only memory cost is the `BufferedInputStream`'s buffer. – user207421 Jan 15 '17 at 02:34
  • @EJP And roughly how much is that cost? Thanks! – Allen Ai Jan 15 '17 at 02:37

1 Answers1

2

You are right. RandomAccessFile is basically only Wrapper for actual Files with not much internal state besides the current pointer. All read/write methods require you to supply it with your own arrays into which data should be loaded.

Also, this question was already answered Java : Read last n lines of a HUGE file Does RandomAccessFile in java read entire file in memory?

Timmeey
  • 363
  • 3
  • 9