如何使用C#插入字符的文件如何使用、字符、文件

2023-09-02 21:30:39 作者:我穿什么衣服关学校毛事

我有一个巨大的文件,在那里我有在特定位置中插入某些字符。什么是做最简单的方法,在C#中,而无需再次改写整个文件。

I have a huge file, where I have to insert certain characters at a specific location. What is the easiest way to do that in C# without rewriting the whole file again.

推荐答案

文件系统不支持在文件中间插入数据。如果你真的有需要,可以写入到一个排序的一种方式的文件,我建议你考虑使用嵌入式数据库。

Filesystems do not support "inserting" data in the middle of a file. If you really have a need for a file that can be written to in a sorted kind of way, I suggest you look into using an embedded database.

您可能想看看 SQLite的或的的BerkeleyDB 。

话又说回来,你可能会和一个文本文件或旧的二进制文件进行工作。在这种情况下,你唯一的选择就是重写文件,至少从插入点到末尾。

Then again, you might be working with a text file or a legacy binary file. In that case your only option is to rewrite the file, at least from the insertion point up to the end.

我会看着的FileStream 类做的随机I / O在C#。

I would look at the FileStream class to do random I/O in C#.

 
精彩推荐