how to write content in a Specific position in a File

You can’t insert data into a file… file systems (in general) simply don’t support such an operation. Typically you’d open one file for reading and another for writing, copy the first part of the file from one stream to the other, write the extra part, then copy the second part of the file.

If you’re trying to replace the original file, you’d then need to delete it and move the new file into place.

Sometimes it may be simpler to read the whole file into memory in one go – it depends on exactly what you’re trying to do, and how big the file is.

Leave a Comment