用户操作
[即时聊天] [发私信] [加为好友]
爱你网
爱你网的公告








一个不错的P2P软件,里面肯定有你要的资源

我的爱你网,讨论.Net


最近评论
hhshang:楼主你做过这个打字程序,如果做了,可不可以发一份给我学习一下呀,我的邮箱是:zeng_xianchun@126.com
yw2008wy:写得不错,我还没有试试,不过挺感谢帖出来
zq32206124:英文看不懂啊
zq32206124:英文看不懂啊
jing_cai:谢谢你的无私奉献!
文章分类
收藏
相册
Csdn专用
个人专用
XML相关资料
XML Server与XML-enabled Web Server介绍
xmlhttp发送 xml 例子详解
在Asp.net里显示XML格式内容.
树的资料
asp.net中的treeview 怎么用
数据库连接
CSDN数据库连接大全
DSN方式连接数据库
杂类
100分问一个突然出现的Cookie问题,关于添加/删除Cookie的。
c#存取图片 (RSS)
我的主页(RSS)
高效.TEXTBLOG技巧终结篇
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

原创 Stream 和 byte[] 之间的转换收藏

新一篇: 精通Javascript动态网页编程  | 旧一篇: JavaScript中的正则表达式解析

/* - - - - - - - - - - - - - - - - - - - - - - - -   * Stream 和 byte[] 之间的转换  * - - - - - - - - - - - - - - - - - - - - - - - */ /// <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; } /* - - - - - - - - - - - - - - - - - - - - - - - -   * Stream 和 文件之间的转换  * - - - - - - - - - - - - - - - - - - - - - - - */ /// <summary> /// 将 Stream 写入文件 /// </summary> public void StreamToFile(Stream stream,string fileName) {     // 把 Stream 转换成 byte[]     byte[] bytes = new byte[stream.Length];     stream.Read(bytes, 0, bytes.Length);     // 设置当前流的位置为流的开始     stream.Seek(0, SeekOrigin.Begin);     // 把 byte[] 写入文件     FileStream fs = new FileStream(fileName, FileMode.Create);     BinaryWriter bw = new BinaryWriter(fs);     bw.Write(bytes);     bw.Close();     fs.Close(); } /// <summary> /// 从文件读取 Stream /// </summary> public Stream FileToStream(string fileName) {                 // 打开文件     FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);     // 读取文件的 byte[]     byte[] bytes = new byte[fileStream.Length];     fileStream.Read(bytes, 0, bytes.Length);     fileStream.Close();     // 把 byte[] 转换成 Stream     Stream stream = new MemoryStream(bytes);     return stream; }

发表于 @ 2008年07月01日 14:05:45|评论(loading...)|编辑|收藏

新一篇: 精通Javascript动态网页编程  | 旧一篇: JavaScript中的正则表达式解析

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 爱你网