【问题标题】:C#: silent access to opened file [duplicate]C#:静默访问打开的文件[重复]
【发布时间】:2012-10-26 21:53:38
【问题描述】:

可能重复:
Read file which is in use?

我有这样的情况/问题:

  1. 当前某个程序打开了一个 txt 文件。该程序将一些日志内容写入文件。
  2. 我的 C# 程序应该以只读模式打开该文件,但访问应该是静默的,并且不应阻止对文件的访问。

哪些 C# 函数可以帮助我?

提前致谢。

【问题讨论】:

  • 说“shhhhhhhhh”
  • -1 用于忽略十几个重复项(123、..)

标签: c# file file-io readonly


【解决方案1】:

您只需将适当的参数传递给File.Open() 方法:

using (var stream = File.Open("path", 
   FileMode.Open, 
   FileAccess.Read, 
   FileShare.ReadWrite))
{
    // You can read, they (logger) can write
}

【讨论】:

    【解决方案2】:

    FileShare 标志允许打开已打开的文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      相关资源
      最近更新 更多