文件非占用读取
非占用方式:
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();