c# byte转stream 和 stream 转 bye
Stream 和 byte[] 之间的转换
/* - - - - - - - - - - - - - - - - - - - - - - - -
* Stream 和 byte[] 之间的转换
* - - - - - - - - - - - - - - - - - - - - - - - */
/// <summary>
/// 将 Stream 转成 byte[]
/// </summary>
public byte[] StreamToBytes(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}
/// <summary>
/// 将 byte[] 转成 Stream
/// </summary>
public Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
}
相关文章
文章评论
热门评论
暂无评论


看了一下,我这个百度联盟的账号上一次申请的日期是2008年10月14日,距今天也有11年多了.用之前的账号登录百度...
今天有幸参加了腾讯大讲堂深圳站.架构之美:开放环境下的网络架构的讲座.很高兴.由于离腾讯公司只有两个站的...
来湖北的当天高铁是到的武汉,我还在武汉溜达了一圈,还是没带口罩的情况下,现在想想真的挺害怕的,你说如果当时...
