Stream 和 byte[] 之间的转换
作者:互联网
1.Stream转byte[],注意设置当前流的位置为流的开始
Stream saveStream = new MemoryStream(); doc.SaveToStream(saveStream, FileFormat.Auto); // 设置当前流的位置为流的开始 saveStream.Seek(0, SeekOrigin.Begin); byte[] fileContent = new byte[saveStream.Length]; saveStream.Read(fileContent, 0, fileContent.Length); saveStream.Dispose();
2.byte[]转Stream
var bytes =new bytes[length]; Stream stream = new MemoryStream(bytes);
标签:转换,saveStream,Stream,bytes,fileContent,new,byte 来源: https://www.cnblogs.com/YCiCi/p/12525864.html