文件非占用读取

文件非占用读取

非占用方式:

FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
//按行读取
 string strLine = sr.ReadLine();
//关闭读写流和文件流
sr.Close();
fs.Close();

占用方式:

FileStream fs = new FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
//按行读取
 string strLine = sr.ReadLine();
//关闭读写流和文件流
sr.Close();
fs.Close();
posted @ 2021-06-22 10:00  码农阿亮  阅读(196)  评论(0编辑  收藏  举报