Files don't support insertion or deletion of content except at the end of the file. (It's not a limitation of Java but the OS)
To insert text, you must re-write the file (at the least from the point you want to alter) The simplest solution is to copy content to a temporary file, altering/inserting or deleting as required and replacing the original if this is sucessful.