It seems you think that you can use RandomAccessFile to insert bytes. You can't. You can use it to replace bytes or to append bytes to the file but you cannot insert bytes.
One approach you can use is to create a new file by reading the original file a line at a time and writing the lines to the new file after making any modifications you require. Note, this only requires one to hold in memory one line at a time.
Once you have created the new file you can delete the old file and rename the new file. To be safe, rather than deleting the old file one normally renames it to a temporary name and then only delete the temporary file once the new file has been successfully renamed.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.