This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
RandomAcessFile will read or write content in the middle of a file, but it can only replace content of exactly the same length. If you try to replace "hello" with "goodbye" you'll clobber the next couple bytes of whatever followed. You cannot insert or delete content in the middle of a file ... it's just a limitation of the file system. (Some operating systems understand line-oriented files and support such actions.) You're pretty much stuck with reading the whole file, making changes and writing a new file. Such is life.
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