Open file ReadOnly

前端 未结 4 500
臣服心动
臣服心动 2020-11-27 06:09

Currently, this is how I\'m opening a file to read it:

 using (TextReader reader = new StreamReader(Path.Combine(client._WorkLogFileLoc, \"dump.txt\")))
{
           


        
4条回答
  •  生来不讨喜
    2020-11-27 06:32

    Per https://docs.microsoft.com/en-us/dotnet/api/system.io.file.openread?redirectedfrom=MSDN&view=netcore-3.1#System_IO_File_OpenRead_System_String_ File.OpenRead enables read shared access not read/write. This prevents the "other process" from being able to close/reopen/write more data as xbonez wants to permit. hans-passant addresses what was requested.

    Per the referenced documentation: This method is equivalent to the FileStream(String, FileMode, FileAccess, FileShare) constructor overload with a FileMode value of Open, a FileAccess value of Read and a FileShare value of Read.

提交回复
热议问题