There are several ways to do this - but I am not clear exactly what you are asking.
Typically, to randomly insert data into a file in the simplest case means you are going to re-write the file.
If the file is relatively small, you would read in the entire file into a string (or array or whatever mechanism that you choose), determine the location where you want to insert the text and modify the string by inserting that text, and then output the file.
If the file is large you might want to read the file in one line at a time (or one chuck at a time or whatever mechanism you want to use) and stream it right back out to another file, until you find the place you need to insert your text - then output that to the new file, then continue to read the original file outputing it into the new file. If that makes sense. When done - you kill the old file and rename the new one.
Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems