乐趣区

关于c#:C-Stream-保存为文件

首先把 Stream 读到 byte 数组中,而后再用 BinaryWriter 写入到二进制文件:

using System.IO;

// streamFile 是 Stream 类型

byte[] bytes = new byte[streamFile.Length];
streamFile.Read(bytes, 0, bytes.Length);
streamFile.Seek(0, SeekOrigin.Begin);
FileStream fs = new FileStream("D:/a.jpg", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(bytes);
bw.Close();
fs.Close();
退出移动版