文件正由另一进程使用,因此该进程无法访问该文件
原来是构造System.IO.FileStream时,使用的方法有问题
一开始是直接使用
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,这样的话,就可以打开了
![](http://v.t.qq.com/sign/zhikuo/c292afa12ad098506bf6828e727a304dd5b5d7b5/1.jpg)
![](http://service.t.sina.com.cn/widget/qmd/1747973797/7f8d4909/10.png)
![](http://service.t.sina.com.cn/widget/qmd/2615575170/c63cf5f5/1.png)
![](http://service.t.sina.com.cn/widget/qmd/2598672782/6c8e236a/1.png)
网站制作-网站建设-公司网站-产品销售网站-产品展示网站-企业宣传网站-网店-网上商城-信息分类网站-QQ471226865