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.
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.