var bytes = new byte[fileLenght+10]; var numBytesToRead = (int)fileLenght; var numBytesRead = 0; using (fs) { do { int n = fs.Read(bytes, numBytesRead, 10); numBytesRead += n; numBytesToRead -= n; } while (numBytesToRead > 0); fs.Close(); }
https://docs.microsoft.com/zh-cn/dotnet/api/system.io.stream.read?redirectedfrom=MSDN&view=netframework-4.7.2#System_IO_Stream_Read_System_Byte___System_Int32_System_Int32_
http://www.cnblogs.com/JimmyZheng/archive/2012/03/17/2402814.html