文件流
1.创建一个文件流。
FileStream fs=new FileStream(path,FileMode.Create,FileAccess.Write);
byte[] buffer=Encoding.UTF8.GetBytes(txt);
2、读取文件或者写文件
参数一:表示byte[]数组
参数二:表示要从该byte[]数组的第几个下标开始写入,一般为零
参数三:要写入的字节个数
fs.Write(buffer,0,buffer.Length);
3、关闭文件流
fs.Flush();//清空缓存区,就是将缓存区里的内容直接写到磁盘上。
fs.Close(); //关闭流
fs.dispose() //释放相关资源
使用Using可以省去dispose(); //使用Using必须实现Idisposable接口
Using(FileStream fs=new FileStream(path,FileMode.Create,FileAccess.Write)
{
文件操作程序
流是指一连串流动的字符,是以先进先出方式发送信息的通道

相关文章:

  • 2022-01-13
  • 2021-07-18
  • 2021-06-01
  • 2021-12-16
  • 2021-10-26
  • 2022-02-20
  • 2021-10-24
猜你喜欢
  • 2021-08-10
  • 2021-09-07
  • 2022-01-18
  • 2021-12-04
  • 2021-12-11
相关资源
相似解决方案