从流中固定读取

读取固定长度

private static byte[] ReadBytes(Stream stream, int count)
{
    var output = new byte[count];
    var total = 0;
    while (total < count)
    {
        var read = stream.Read(output, total, count - total);
        if (read == 0)
        {
            throw new EndOfStreamException();
        }
        total += read;
    }
    return output;
}
posted @ 2024-09-30 17:47  pojianbing  阅读(3)  评论(0编辑  收藏  举报