首页 > 其他 > 详细

二进制流互转

时间:2015-09-09 19:12:50      阅读:225      评论:0      收藏:0      [点我收藏+]
 1  /// <summary>
 2         /// 二进制数组转流
 3         /// </summary>
 4         /// <param name="bytes"></param>
 5         /// <returns></returns>
 6         public static Stream BytesToStream(byte[] bytes)
 7         {
 8             Stream stream = new MemoryStream(bytes);
 9             return stream;
10         }
11 
12         /// <summary>
13         /// 流转二进制数组
14         /// </summary>
15         /// <param name="theStream"></param>
16         /// <returns></returns>
17         public static byte[] StreamToBytes(Stream theStream)
18         {
19             int index;
20             MemoryStream tempStream = new MemoryStream();
21             while ((index = theStream.ReadByte()) != -1)
22             {
23                 tempStream.WriteByte(((byte)index));
24             }
25             return tempStream.ToArray();
26         }

 

二进制流互转

原文:http://www.cnblogs.com/liuxiaoji/p/4795521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!