The times that RandomAccessFile will work for you are few and far between. You can only replace old content with new content of exactly the same length. Ok, it is possible to shift data around to accomodate length changes, but the complexity is high and the performance is questionable.
It's a lot more likely that you'll read the entire file, pass most content unchanged to a new file, identify and modify some content before writing it to the new file. Or if the size is manageable, read the entire file into memory, work on it in memory for a while, then rewrite the entire file.
Here's a favorite trick for rewriting a file that assures you always have a safe copy of the old and/or new data:
read original write temp rename original to backup rename temp to original erase backup
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi