C#Stream 和 byte[] 之间的转换
2016-06-30 15:41
507 查看
/* - - - - - - - - - - - - - - - - - - - - - - - - * Stream 和 byte[] 之间的转换 转载请注明来自 http://www.shang11.com * - - - - - - - - - - - - - - - - - - - - - - - */ /// <summary> /// 将 Stream 转成 byte[] /// </summary> public byte[] StreamToBytes(Stream stream) { byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); // 设置当前流的位置为流的开始 stream.Seek(0, SeekOrigin.Begin); return bytes; } /// <summary> /// 将 byte[] 转成 Stream /// </summary> public Stream BytesToStream(byte[] bytes) { Stream stream = new MemoryStream(bytes); return stream; }
相关文章推荐
- Android之使用Http协议实现文件上传功能
- Java IO与NIO的一些文件拷贝测试
- Silverlight将图片转换为byte的实现代码
- Stream、WshShell、WshUrlShortcut对象及Shell.Application的参数与使用
- 在VBS中定义字节数组Byte()介绍
- Convert 将 FAT 和 FAT32 卷转换为 NTFS
- ASCII码表 和 说明
- Node.js中的流(Stream)介绍
- Sql Server 和 Access 操作数据库结构Sql语句小结
- php中stream(流)的用法
- php错误提示failed to open stream: HTTP request failed!的完美解决方法
- PHP 和 MySQL 开发的 8 个技巧
- Asp.Net 和 AJAX.Net 的区别第1/2页
- 读写xml所有节点个人小结 和 读取xml节点的数据总结
- HTTP_HOST 和 SERVER_NAME 的区别详解
- NextRecordset 和 GetRows 双簧合奏
- showModalDialog 和 showModelessDialog
- 终于了解了下.net 和 j2ee的区别
- Aptana 和 JSEclipse 的选择
- document 和 document.all 分别什么时候用