如何编辑C#中特定位置的二进制文件中的数据 [英] How to edit data in a binaryfile on a specific position in C#
问题描述
我必须通过上传二进制文件来编辑特定位置的二进制文件中的特定数据。如何在c#中执行此操作。
我尝试过:
代码
<
使用(FileStream sr = File.OpenRead(someFile.dat))
{
sr.Seek(100,SeekOrigin.Begin);
int read = sr.ReadByte();
// ...
}
>
而不是寻找一个流,只需阅读整个dtaa:
byte [] data File.ReadAllBytes(pathToFile);
然后,您可以使用数组索引分别访问每个字节,并使用File.WriteAllBytes保存更改后的数据结束。
I have to edit a particular data in a binary file at a particular position by uploading a binary file.How can i do this in c#.
What I have tried:
code
<
using (FileStream sr = File.OpenRead("someFile.dat"))
{
sr.Seek(100, SeekOrigin.Begin);
int read = sr.ReadByte();
//...
}
>
Instead of seeking a stream, just read the whole dtaa in:
byte[] data File.ReadAllBytes(pathToFile);
You can then use the array index to access each byte individually, and use File.WriteAllBytes to save the changed data when you are finished.
这篇关于如何编辑C#中特定位置的二进制文件中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!