.net stream 转成 bytes[] 的实例和注意事项

public static byte[] Stream2Bytes(ref Stream s)
        {
            if (s == null)
            {
                return null;
            }
            s.Seek(0, SeekOrigin.Begin);
            byte[] bytes = new byte[s.Length];
            s.Read(bytes, 0, bytes.Length);
            s.Close();
            return bytes;
        }


注意在stream转换之前一定要先把stream 定位到 头

原文地址:https://www.cnblogs.com/rav009/p/5131148.html