zoukankan      html  css  js  c++  java
  • 网络流转换为Byte数组

     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         }
  • 相关阅读:
    The AndroidManifest.xml File
    handlebars简单用法
    高性能跨语言模板引擎Crox
    C++17 新特性
    C++ 14新特性
    [lua]笔记
    [lua]笔记
    delphi关键字
    delphi 基础
    TCP/UDP
  • 原文地址:https://www.cnblogs.com/lyghost/p/4810741.html
Copyright © 2011-2022 走看看