我可以简单地“读取"正在使用的文件吗? [英] Can I simply 'read' a file that is in use?

查看:20
本文介绍了我可以简单地“读取"正在使用的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 StreamReader 读取文件,但它始终被另一个进程使用,因此出现此错误:

I am trying to use a StreamReader to read a file, but it is always in use by another process so I get this error:

进程无法访问文件'arfjwknasgmed17C$FLAG条件CP-ARFJN-FLAG.XLS' 因为它正在被另一个进程使用.

The process cannot access the file 'arfjwknasgmed17C$FLAG CONDITIONCP-ARFJN-FLAG.XLS' because it is being used by another process.

有没有办法不用复制就可以阅读?还是那是我唯一的选择?

Is there a way I can read this without copying it? Or is that my only option?

推荐答案

只有在打开文件的程序首先指定了对该文件的读取共享权限时,您才能读取该文件.

You can read the file only if the program that opened the file first specified read sharing rights on that file.

如果该文件确实没有读取共享权限,您将无法首先复制它.

If the file does indeed have no read sharing rights though, you wouldn't be able to copy it in the first place.

如果您指定的共享权限与已打开文件的程序的共享权限冲突,则您可能无法访问该文件.例如,如果已打开它的程序未授予写访问权限,则您无法授予写访问权限.

You may not be able to access a file if you are specifying a sharing right that conflicts with the sharing right of a program that already has the file opened. For example you can't grant write access if the program that already has it opened isn't granting write access.

如果最初打开文件的程序支持卷影复制 (VSS),您也可以使用 VSS 来访问文件.

If the program that opened the file in the first place supports Volume Shadow Copy (VSS), you can also use VSS to gain access to the file.

有些商业软件驱动程序允许您访问此类文件,即使它们正在使用中.您以前可以通过 St-Bernards 获得 Open File Manager,也可以使用 File Access Manager (FAM) 由 VisionWorks Solutions Inc. 提供.这些驱动程序通常由 OEM 提供给备份软件公司以包含在他们的产品中.

There are commercial software drivers that allow you to access such files, even when they are in use. You used to be able to get Open File Manager by St-Bernards, and you can also use File Access Manager (FAM) by VisionWorks Solutions Inc. These drivers are typically OEM'ed to backup software companies for inclusion in their products.

VSS 的工作原理是告诉已经打开文件的程序另一个程序要从文件中读取.然后 VSS 会复制该文件并让您从该副本中读取.VSS 不适用于旧版应用程序.

VSS works by telling the program that has the file opened already that another program would like to read from the file. VSS then does a copy of the file and lets you read from this copy. VSS does not work for legacy applications.

FAM 通过指定可以独占打开和锁定文件的应用程序允许列表",透明地适用于旧版和非旧版程序.只有此列表中的程序才能访问这些文件.当文件被打开时,它会进入缓存模式,以便您获得文件的副本,就像文件的备份/打开"开始时一样.此时,最初打开文件的程序会看到文件的实际情况,而允许列表中的第二个程序会看到文件打开/备份"发生时的情况.这确保了文件的一致性.

FAM transparently works for legacy and non-legacy programs alike by specifying an 'allowed list' of applications that can access exclusively opened and locked files. Only programs in this list are allowed access to these files. When a file is being opened, it goes into cache mode so that you will obtain a copy of the file as it was when the 'backup/open' of the file started. At this point the program that originally opened the file sees the file as it actually is, and the second program in the allowed list, sees the file as it was when the 'open/backup' of the file happened. This ensures consistency of the file.

这篇关于我可以简单地“读取"正在使用的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆