How can I insert or remove bytes from the middle of a large file in .NET

前端 未结 4 1861
自闭症患者
自闭症患者 2021-01-12 08:12

Is it possible to efficiently insert or remove bytes from the middle of a large file, and if so how? Or am I stuck rewriting the entire file after the point

4条回答
  •  伪装坚强ぢ
    2021-01-12 08:22

    There is no way to insert data or remove data in O(1) in C# nor C++ nor any language with standard APIs or class libraries.

    The best you could do is have some kind of file format that you define yourself, it could support O(1) insertions and removal. But you'd have to probably deal with fragmentation.

    You could perhaps also look at an SQL database like sqlite which would take care of the complexities for you.

提交回复
热议问题