.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 定位到 头

posted @ 2013-06-21 16:21  爱知菜  阅读(346)  评论(0编辑  收藏  举报