• 文件非占用读取


    文件非占用读取

    非占用方式:

    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();

    技术的发展日新月异,随着时间推移,无法保证本博客所有内容的正确性。如有误导,请大家见谅,欢迎评论区指正!
    我创建了一个.NET开发交流群,用于分享学习心得和讨论相关技术难题。欢迎有兴趣的小伙伴扫码入群,相互学习!

  • 相关阅读:
    第五章4
    第五章3
    第五章2
    第五章1
    第四章14
    第四章13
    第四章12
    第四章11
    第五章例5-6
    第五章例5-4
  • 原文地址:https://www.cnblogs.com/wml-it/p/14917216.html
Copyright © 2020-2023  润新知