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;
}
相关文章
文章评论
热门评论
暂无评论


近期有好几个同学问我创业相关的问题,然后也跃跃欲试.哥就写一下自己的一些经验吧.不过哥得提醒啊:创业有风险...
随着二维码的普及,越来越多的场合需要用到二维码,比如产品介绍、网站访问、支付等等。为了满足人们对美的追...
visual studio 2022 在运行web项目后,页面报错:HTTP Error 500.24 - Internal Server Error 检测到在集成的...
