首页 > Windows开发 > 详细

C# 将 Stream 写入文件

时间:2017-08-08 14:35:35      阅读:509      评论:0      收藏:0      [点我收藏+]

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();

}

C# 将 Stream 写入文件

原文:http://www.cnblogs.com/niuniu0108/p/7306350.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!