从StreamReader流写入文件

时间:2012-03-22 11:18:18

标签: c# asp.net wcf stream

我目前正在尝试从WCF下载音频曲目,我需要一些帮助将其写入硬盘,如何配置streamwriter或其他在webApp中执行此操作?

// Use Service to download stream (returns System.IO.Stream) 
Stream stream = MyService.Download(("1231"));
// ReadStream
StreamReader reader = new StreamReader(stream);
reader.ReadToEnd();

// Write this stream to a file/Hard disk
???

1 个答案:

答案 0 :(得分:29)

Stream stream = MyService.Download(("1231"));
using (Stream s = File.Create(path))
{
    stream.CopyTo(s);
}