使用文件C# [英] working with files c#

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

问题描述

你好.

我有一个问题,我该如何写二进制或文本文件,但不能覆盖或仅添加.
我有一个包含数字列表的文件,我想更改其中一个(NUMBERS)或一组而不更改其他数字.

THX.

Hello.

I have a question about how can i write to file binary or text but not overwrite or just add.
I have file that contain a list of numbers and i wanna change one of them(NUMBERS) or a group of them without changing the others .

THX.

推荐答案

基本上,您不能.无法在文本或二进制文件的中间进行插入-您必须从该点到文件末尾重新编写文件.

如果您经常这样做,则可能要考虑使用数据库(.NET中包含SQLCE)并以这种方式存储它们.
您可以使用XML输出,但这只会为您做重写-它也不能插入.
Basically, you can''t. There is no way to do an insert in the middle of a text or binary file - you have to re-write the file from that point to the end of file.

If you are doing this often, you might want to think about using a database (SQLCE is included with .NET) and storing them that way.
You could use XML output, but that will just do the re-write for you - it can''t insert either.


您必须加载整个文件,更改所需的部分进行更改,然后将整个文件保存回驱动器.
You have to load the entire file, change the part you want to change, and then save the entire file back to the drive.


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

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