问题描述
我有一个巨大的文件,我必须在特定的位置插入某些字符。在C#中没有重写整个文件的最简单的方法是。
文件系统不支持插入数据在文件的中间。如果您真的需要一个可以按照排序方式写入的文件,建议您查看使用嵌入式数据库。
您可能需要请查看或。
再次,您可能正在使用文本文件或旧的二进制文件。在这种情况下,您唯一的选择是重写文件,至少从插入点到结尾。
我将看看类在C#中执行随机I / O。 p>
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.
You might want to take a look at SQLite or 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.
I would look at the FileStream class to do random I/O in C#.
这篇关于如何使用C#将文字插入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!