跳到主要内容

Stream

ToBytes

备注

将流转为 byte[]

var filePath = "./XXXXX";
using var fs = new FileStream(filePath, FileMode.OpenOrCreate);
var bytes = fs.ToBytes();

ToStream

备注

将byte[] 转为流对象

var filePath = "./XXXXX";
using var fs = new FileStream(filePath, FileMode.OpenOrCreate);
var stream = fs.ToBytes().ToStream();

SaveTo

备注

可以将流对象直接保存为文件

var filePath = "./XXXXX";
using var fs = new FileStream(filePath, FileMode.OpenOrCreate);
string toFile = "./PPPPP";
fs.SaveTo(toFile);
fs.ToBytes().SaveTo(toFile);

Seek

备注

将流指针移动到指定位置

var filePath = "./XXXXX";
using var fs = new FileStream(filePath, FileMode.OpenOrCreate);
fs.SeekToEnd();
fs.SeekToOrigin();
fs.SeekTo(0);

Clear

备注

清空流

stream.Clear();