C#文件流写入方法

stream为服务端接收的文件流
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);


var pathHead = HttpContext.Current.Request.PhysicalApplicationPath;
if (!Directory.Exists(path))
   Directory.CreateDirectory(path);
var resultPath = path + "文件.后缀";
var fileStream = new FileStream(resultPath, FileMode.Create, FileAccess.ReadWrite);
//文件写入
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Flush();
fileStream.Close();

  

posted @ 2016-06-28 17:26  有梦想的L先生  阅读(2533)  评论(0编辑  收藏  举报