System.IO.IOException:The process cannot access the file 'XX.xml' because it is being used by another process. 解决方案
2012-04-24 17:01
711 查看
有时候用StreamReader去读取xml文件时,会出现System.IO.IOException:The process cannot access the file 'XX.xml' because it is being used by another process. 错误,这是因为
reader在读取完毕后,没有没有关闭reader和释放资源,xml文件在被占用着,所以报错。
在后面增加代码
string str = ""; StreamReader reader = new StreamReader( "E:\test.xml", Encoding.Default ); str = reader.ReadToEnd();
reader在读取完毕后,没有没有关闭reader和释放资源,xml文件在被占用着,所以报错。
在后面增加代码
reader.Close(); reader.Dispose();
相关文章推荐
- C#使用Create创建文件后,报The Process cannot access the file because it is being used by another process的异常
- FileStream:The process cannot access the file because it is being used by another process
- 【转】IIS: The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
- Error: because it is being used by another process
- Visual studio bin/Debug/… because it is being used by another process
- 处理文件时遇到:The process cannot access the file because it is being used by another process.
- C# The process cannot access the file because it is being used by another process
- C#使用Create创建文件后,报The Process cannot access the file because it is being used by another process的异常
- The process cannot access the file because it is being used by another process.
- FileStream:The process cannot access the file because it is being used by another process
- 解决编译报错:Unable to copy file, because it is being used by another process.
- Bug on Build Solution: "Unable to copy file... because it is being used by another process.."
- the process cannot access the file because it is being used by another process
- the process cannot access the file because it is being used by another process
- the process cannot access the file because it is being used by another process
- the process cannot access the file because it is being used by another process
- Solution: The process cannot access the file [filename] because it is being used by another process.
- IIS:The process cannot access the file because it is being used by another process.
- the process cannot access the file because it is being used by another process
- 文件流操作,报“because it is being used by another process. ”错误解决