You can't really do this mostly.
If you have liines of fixed lengths then you can do this with RandomAccessFile. Otherwise you cannot. Filesystems do not work this way. You cannot arbitrarily inject or remove bytes from the middle of a file. You can replace them but that''s usually unhelpful.
You must rewrite the entire file replacing the line you want with your new one.
Sure. Create a new output file. Then copy the lines up to the line needing replaced, insert the replacement, and copy the following lines. (Use a BufferedReader).
Then delete or rename to old file, and rename the new file to the old one's name.
Swallowing the whole file is slightly grotty. First off, that limits your file size. Second, if you get an IO error (e.g. disk full), or the program otherwise crashes during the write then you can lose the file.
Using file generations is safer, and can deal with huge files without using huge amounts of memory.