I’m using a FileReader wrapped in a LineNumberReader to index a large text file for speedy access later on. Trouble is I can’t seem to find a way to read a specific line number directly. BufferedReader supports the skip() function, but I need to convert the line number to a byte offset (or index the byte offset in the first place).
I took a crack at it using RandomAccessFile, and while it worked, it was horribly slow during the initial indexing. BufferedReader’s speed is fantastic, but… well, you see the problem.
Some key info:
- The file can be any size (currently 35,000 lines)
- It’s stored on Android’s internal filesystem (via getFilesDir() to be exact)
- The formatting is not fixed width, unfortunately (hence the need to read by line)
Any ideas?
Describes an extended RandomAccessFile with buffering semantics