C# 将 Stream 写入文件

时间:2017-08-08 14:35:35   收藏:0   阅读:509

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

}

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!