如何在c#win中逐步读取文件的字节。形成 [英] How to read bytes of a file step by step in c# win. form
本文介绍了如何在c#win中逐步读取文件的字节。形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 8 GB 的大文件,想要读取8个部分但问题是我不知道如何读取部分文件有人可以帮助我吗。
注意: - 这里的文件读取是指将文件转换为字节数组,可以这样实现: -
I have a large file of 8 GB and want to read in 8 parts but problem is i don't know how to read file in parts can someone help me here.
Note:-File reading here refers to converting file into byte array which can be achieved like this:-
File.ReadAllBytes("Path");
提前致谢
Thanks in advance
推荐答案
使用 Stream.Read [ ^ ]代替:
Use Stream.Read[^] instead:
byte[] buffer = new buffer[blockSize];
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
try
{
int count;
while ((count = fileStream.Read(buffer, sum, blockSize)) > 0)
{
... do something with the block.
}
}
finally
{
fileStream.Close();
}
这篇关于如何在c#win中逐步读取文件的字节。形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文