It sounds like what you want to do is just prevent any modifications to the file while you are reading from it. This is typically accomplished by locking the file, so that only your process can access it. As an example (using FileLock from java.nio)
try{
File file = new File("randomfile.txt");
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
FileLock lock = channel.lock();//Obtain a lock on the file
try{
//Do your things
}
finally{
lock.release();//Release the lock on the file
channel.close();
}
}
catch (IOException e) {
e.printStackTrace();
}