读取数据块的二进制文件C# [英] read chunks binary file C#
本文介绍了读取数据块的二进制文件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何读取5megabytes大块在C#中的二进制文件?
How do I read chunks of 5megabytes in a binary file in C#?
对于每块我需要做的事...
请帮帮我!
For every chunk I need to do a thing... Please Help me!
推荐答案
您可以使用的 的FileStream
读取二进制文件,然后做你它的处理。这里有一个例子:
You can use a FileStream
to read a binary file then do your processing on it. Here's a example:
using (var inFileSteam = new FileStream(@"C:\path\to\file.bin", FileMode.Open))
{
byte[] buffer = new byte[5 * 1024 * 1024]; // 5MB in bytes is 5 * 2^20
int bytesRead = inFileSteam.Read(buffer, 0, buffer.Length);
while (bytesRead > 0)
{
for (int i = 0; i < bytesRead; i++)
{
if (buffer[i] == 0x28) // 0010 1000 in binary
{
// replace for example or any other manipulation
buffer[i] = 0x00;
}
}
outFileStream.Write(buffer, 0, bytesRead);
bytesRead = inFileSteam.Read(buffer, 0, buffer.Length);
}
}
这篇关于读取数据块的二进制文件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文