问题描述
Helloo Everbody
我正在尝试为我的大学项目构建AV,并且在扫描过程中出现异常-访问被拒绝,文件被另一个进程使用,因此无法扫描该文件.我也使用Fileshare.ReadWrite但没有用. 大多数情况下使用C:驱动器文件.
Helloo Everbody
I am trying to build an AV for my college project and during scanning I am getting exception-Access denied,file is used by another process and hence can''t scan the file.I also used Fileshare.ReadWrite but of no use.It''mostly with C: drive files.
推荐答案
FileStream writer = new FileStream("C:\theFile", FileMode.Open, FileAccess.Write, FileShare.Read);
然后,您可以使用以下文件打开文件:
Then you can open the file using:
FileStream reader = new FileStream("C:\theFile", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
请注意,您始终可以尝试以只读模式打开文件,如果成功,还取决于文件的初始用户的状态.
如果这样做不适合您,则需要找出谁持有该文件.如果您知道,那您就离解决方案更近了一步.
您可以使用句柄 [ ^ ]查找该应用程序.
根据您发现的内容,您可以采取适当的措施;如果事实证明您自己的应用程序已经具有该文件的句柄,则您可能只是有多个线程在执行相同的操作……真的一样:).
干杯,AT
Note that you can always try to open the file in read only mode, if you succeed also depends on how nice the initial user of the file is.
If this doesn''t do it for you, you need to sort out who is holding the file. If you know that, you''re one step closer to the solution.
you can use Handle[^] to find the application.
Depending on what you find you can take the appropriate action; if it turns out that your own applicaiton already has a handle to the file you might be just have multiple threads doing the same... really the same :).
Cheers, AT
FileStream fs = new FileStream(@"<file path>", FileMode.Open, FileAccess.Read, FileShare.Read);
因此< file path =">应该是您要访问的文件.
然后应该可以根据需要使用"fs"对象.
问候.
So <file path=""> should be file that you want to access.
then should be able to use "fs" object as you want.
Regards.
这篇关于如何读取另一个进程已经使用的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!