c# 正由另一进程使用,因此该进程无法访问该文件
WebRequestrequest=WebRequest.Create(""+url+"");WebResponseresponse=request.GetRespons...
WebRequest request = WebRequest.Create(" " + url + " ");
WebResponse response = request.GetResponse();
Stream reader = response.GetResponseStream();
FileStream writer = new FileStream("" + path + "\\" + pic_name + "", FileMode.Create, FileAccess.ReadWrite,FileShare.ReadWrite);
// FileStream writer = new FileStream("" + path + "\\" + pic_name + "", FileMode.Create
// Bitmap bt = new Bitmap(writer);
byte[] buff = new byte[512];
int c = 0; //实际读取的字节数
while ((c = reader.Read(buff, 0, buff.Length)) > 0)
{
writer.Write(buff, 0, c);
}
} 展开
WebResponse response = request.GetResponse();
Stream reader = response.GetResponseStream();
FileStream writer = new FileStream("" + path + "\\" + pic_name + "", FileMode.Create, FileAccess.ReadWrite,FileShare.ReadWrite);
// FileStream writer = new FileStream("" + path + "\\" + pic_name + "", FileMode.Create
// Bitmap bt = new Bitmap(writer);
byte[] buff = new byte[512];
int c = 0; //实际读取的字节数
while ((c = reader.Read(buff, 0, buff.Length)) > 0)
{
writer.Write(buff, 0, c);
}
} 展开
1个回答
展开全部
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,这样的话,就可以打开了
这个方法打开文件的时候是以只读共享的方式打开的,但若此文件已被一个拥有写权限的进程打开的话,就无法读取了,
因此需要使用
System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open,System.IO.FileAccess.Read,FileShare.ReadWrite);
设置文件共享方式为读写,FileShare.ReadWrite,这样的话,就可以打开了
追问
我是这样写的啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询