码迷,mamicode.com
首页 > 编程语言 > 详细

网络流转换为Byte数组

时间:2015-09-15 18:11:45      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

 1 /// <summary>
 2         /// 网络流转换为Byte数组
 3         /// </summary>
 4         /// <param name="stream"></param>
 5         /// <returns></returns>
 6         public static byte[] ReadFully(Stream stream)
 7         {
 8             byte[] buffer = new byte[128];
 9             using (MemoryStream ms = new MemoryStream())
10             {
11                 while (true)
12                 {
13                     int read = stream.Read(buffer, 0, buffer.Length);
14                     if (read <= 0)
15                         return ms.ToArray();
16                     ms.Write(buffer, 0, read);
17                 }
18             }
19         }

 

 1 /// <summary>
 2         /// 网络流转换为Byte数组
 3         /// </summary>
 4         /// <param name="stream"></param>
 5         /// <returns></returns>
 6         public static byte[] ReadFully(Stream stream)
 7         {
 8             byte[] img = null;
 9             int size = 1024;
10             int read = 0;
11             MemoryStream ms = new MemoryStream();
12             byte[] buffer = new byte[size];
13             do
14             {
15                 buffer = new byte[size];
16                 read = resst.Read(buffer, 0, size);
17                 ms.Write(buffer, 0, read);
18             } while (read > 0);
19             img = ms.ToArray();      
20         }

 

网络流转换为Byte数组

标签:

原文地址:http://www.cnblogs.com/lyghost/p/4810741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!