If you need access to arbitrary previous parts of the file then it is likely easier to just read the entire file into memory and then begin processing it, you can do that via:
If the file is too big to read in entirely and you both need to stream over it and access individual parts later, you basically have to stream over the file using a BufferedReader and copy the parts you want to keep for later.
But ideally you would be able to avoid having such a data file in production and instead create a optimized file that only contains what is needed, but this itself might involve streaming over the file and writing out a smaller file.
You also could use memory mapping, but that is less portable and involves its own tricky semantics.