带有锁定文件的 FileStream [英] FileStream with locked file
问题描述
我想知道是否可以将只读 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)
文件访问
确定 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.
这篇关于带有锁定文件的 FileStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!