惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Jina AI
Jina AI
GbyAI
GbyAI
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
P
Proofpoint News Feed
The Cloudflare Blog
H
Help Net Security
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
量子位
博客园 - 聂微东
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
月光博客
月光博客

博客园 - 三聪

如何利用.Net内置类,解析未知复杂Json对象 制作等比环切缩缩图 让window.setTimeout等支持带参数方法 利用NewID()生成随机数 创建缩略图 winform给html提供接口 IE下记住文本框的光标位置 ie下取得iframe里面内容 短网址计算 树冲突 截图片 学习Objective-C: 入门教程 C#根据字节数截取字符串 asp.net本地和全局资料文件的读取方法 jquery实现点击空白的事件 Asp.net 利用Jquery Ajax传送和接收DataTable 用一个最简单方法解决asp.net页面刷新导致数据的重复提交 SOS"未将对象引用设置到对象的实例" .NET调PHP Web Service的典型例子
流操作
三聪 · 2014-04-30 · via 博客园 - 三聪
 #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