FILESTREAM与锁定的文件文件、FILESTREAM

2023-09-02 02:04:08 作者:九夏微凉

我想知道是否有可能得到一个只读的FileStream到一个锁定的文件? 我现在得到一个异常,当我尝试读取锁定的文件。

I am wondering if it's possible to get a readonly FileStream to a locked file? I now get an exception when I try to read the locked file.

using (FileStream stream = new FileStream("path", FileMode.Open))

谢谢!

推荐答案

您应该尝试另一个构造。这些都记录在MSDN。

You should try another constructor. They are documented at MSDN.

这一个看起来像一个赌注:

This one looks like a bet:

FileStream Constructor (String, FileMode, FileAccess, FileShare)

MSDN链接

的FileAccess

一个常数,决定了文件可以FileStream对象进行访问。这得到FileStream对象的的CanRead和CanWrite性能。 CanSeek为真,如果路径指定的磁盘文件。

A constant that determines how the file can be accessed by the FileStream object. This gets the CanRead and CanWrite properties of the FileStream object. CanSeek is true if path specifies a disk file.

文件共享

一个常数,决定了该文件将被进程共享。

A constant that determines how the file will be shared by processes.

 
精彩推荐
图片推荐