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

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

问题描述

我有一个巨大的文件,在那里我有在特定位置中插入某些字符。什么是做最简单的方法,在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#.

这篇关于如何使用C#插入字符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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