Frage

I'm new to binary files, My binary file is written in a length indicator way and I want to know if there is a way I can update it (writing to it) without overwriting it (shifting the text)? And how deleting can be done (deleting with shifting backwards)?

War es hilfreich?

Lösung

You can't to that. If you want to delete a piece of data in your file, you will need to re-write the remainder of the file.

pseudo-code:

- Open original file for read
- Open temp file for write
- While data in original file
    - If original file data is needed
        - Write data to temp file
- Delete original file
- Rename temp file to original file name
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top