.net提示“正由另一进程使用,因此该进程无法访问该文件”怎么办?

如题所述

System.IO.FileStream fs = new System.IO.FileStream(fileName,

System.IO.FileMode.Open)

这个方法打开文件的时候是以只读共享的方式打开的,但若此文件已被一个拥有写权限的进程打开的话,就无法读取了。

因此需要使用

System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open,System.IO.FileAccess.Read,FileShare.ReadWrite);

设置文件共享方式为读写,FileShare.ReadWrite,这样的话,就可以打开了。

温馨提示:答案为网友推荐,仅供参考
相似回答