How can I read a text file without locking it?

后端 未结 7 513
梦谈多话
梦谈多话 2020-11-27 02:42

I have a windows service writes its log in a text file in a simple format.

Now, I\'m going to create a small application to read the service\'s log and shows both th

相关标签:
7条回答
  • 2020-11-27 03:38

    I remember doing the same thing a couple of years ago. After some google queries i found this:

        FileStream fs = new FileStream(@”c:\test.txt”, 
                                       FileMode.Open, 
                                       FileAccess.Read,        
                                       FileShare.ReadWrite);
    

    i.e. use the FileShare.ReadWrite attribute on FileStream().

    (found on Balaji Ramesh's blog)

    0 讨论(0)
提交回复
热议问题