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


我的一个网站天天被爬虫恶意抓取,不胜其烦!可看我前几次写的文章:网站还是继续被恶意爬虫爬取数据 网站还是继...
上次发的文章: 京东金融还信用卡也收手续费了当时京东从不收手续费调到了超过10000元就收手续费.今天看到从1...
今天这边的网络访问淘宝经常出现:504 Gateway Time-outThe gateway did not receive a timely response fro...
