There's no operation for replacing different-sized data in a RandomAccessFile, therefore you have to do it yourself. If the data you are replacing is a different length to the new data, you must move the rest of the file contents appropriately. If the file is known to be small, this is pretty easy. If it could be big, you need to take plenty of care.
In general, it is bad to have a data file structure that requires you to do this type of thing. If you have the opportunity to change the file format, you probably should do so. You could consider allowing enough space for any likely value, and filling unused spaces with some special byte. Or you could go for a more advanced format, using indirection within the file.
On a minor point, you have a bug in your code regarding line endings. You are writing the line ending as '\n', and reading using readLine(). These two are not guaranteed to use the same line endings (I guess they do on the platform you currently use, if you program "works"). In addition,
you should be aware that you are implicitly doing lots of String/byte and byte/String conversions using the JVM's default locale.
[ September 22, 2006: Message edited by: Peter Chase ]