I need to work with large files (lots of GB) and need quick searches to get specific strings on demand.
The idea was to support mapping:
some_key -> byte_location
Where the byte location represents where the line begins in the file.
Edit: The question has changed a bit:
At first I used:
FileInputStream stream = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
FileChannel channel = stream.getChannel();
I noticed that FileChannel.position()it will not return the exact position in which the reader is reading, because it is a "buffered" reader. It reads pieces of a given size (16k here), so what I get from the FileChannel is a multiple of 16k, and not the exact position at which the reader really reads.
PS: file is in UTF-8
source
share