C#文件流写入方法

Posted Reysl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();

  

以上是关于C#文件流写入方法的主要内容,如果未能解决你的问题,请参考以下文章