如何使用C#将文字插入文件 [英] How to insert characters to a file using C#

查看:149
本文介绍了如何使用C#将文字插入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的文件,我必须在特定的位置插入某些字符。在C#中没有重写整个文件的最简单的方法是。

解决方案

文件系统不支持插入数据在文件的中间。如果您真的需要一个可以按照排序方式写入的文件,建议您查看使用嵌入式数据库。



您可能需要请查看 SQLite BerkeleyDB



再次,您可能正在使用文本文件或旧的二进制文件。在这种情况下,您唯一的选择是重写文件,至少从插入点到结尾。



我将看看 FileStream 类在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#将文字插入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆