zoukankan      html  css  js  c++  java
  • 流操作

     #region -- 流操作
    
            /// <summary>
            /// 复制流
            /// </summary>
            public static MemoryStream CopyStream(Stream stream)
            {
                MemoryStream mstream = new MemoryStream();
                CopyStream(stream, mstream);
                return mstream;
            }
    
            /// <summary>
            /// 复制流
            /// </summary>
            public static void CopyStream(Stream source, Stream target)
            {
                byte[] bytes = new byte[1024];//临时字节数据数组
                if (source.CanRead)
                {
                    while (true)
                    {
                        int length = source.Read(bytes, 0, bytes.Length);
                        target.Write(bytes, 0, length);
                        if (length < bytes.Length)
                        {
                            break;
                        }
                    }
                }
            }
            /// <summary>
            /// Stream转字节数组
            /// </summary>
            /// <returns></returns>
            public static byte[] ReadStream(Stream stream)
            {
                using (MemoryStream mstream = new MemoryStream())
                {
                    CopyStream(stream, mstream);
                    return mstream.ToArray();
                }
            }
            #endregion
  • 相关阅读:
    HDU 1003 Max Sum
    HDU 1728 逃离迷宫
    UVA 10057 A midsummer night's dream.
    HDU 1232 畅通工程
    poj3331
    poj3481
    poj1053
    poj3281
    poj3199
    !!! Gridview的多种使用方法总结
  • 原文地址:https://www.cnblogs.com/gateluck/p/3700695.html
Copyright © 2011-2022 走看看