<span style="font-size:18px;"> ///FileStream实例化方法
FileStream fs = File.Open("路径", FileMode.Create, FileAccess.Write);//返回FileStream
FileStream fse = File.OpenRead("路径");//返回只读的FileStream
FileStream fso = File.OpenWrite("路径");//返回只写璘FileStream</span>
<span style="font-size:18px;"> //使用文件流写入文件
FileStream fs = new FileStream("1.txt", FileMode.Create, FileAccess.Write);
//FileMode属性说明
//1、Append
//2、Create
//3、CreateNew
//4、Open
//5、OpenOrCreate
//6、truncate
string msg = "编程语言学习是一个循环渐进的过程";
//把string类型转化为字节数组
byte[] by = System.Text.Encoding.UTF8.GetBytes(msg);
fs.Write(by, 0, by.Length);//写入文件
fs.Dispose();
fs.Close();</span>
<span style="font-size:18px;"> //使用FileStream读取文件
using (FileStream fsRead=new FileStream("1.txt",FileMode.Open,FileAccess.Read))
{
//把字节流放到byte数组中
byte[] strBy = new byte[fsRead.Length];
fsRead.Read(strBy, 0, strBy.Length);
string strMsg = System.Text.Encoding.UTF8.GetString(strBy);//把byte数组转化为字符串
Console.WriteLine(strMsg);
}</span>