Coludn't acces the XML file in Visual Studio c#
执行下面的代码时,打开文件时显示错误它说文件dict.xml已经被某个进程使用了
这里显示错误
FileStream fs = new FileStream("dict.xml", FileMode.Open, FileAccess.Read);
1 2 3 4 5 6 7 8 | FileStream fs = new FileStream("dict.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("dict"); for (i = 0; i <= xmlnode.Count - 1; i++) { w[i] = xmlnode[i].ChildNodes.Item(0).InnerText; m[i] = xmlnode[i].ChildNodes.Item(1).InnerText; } |
如果文件上有其他锁定项,则如果指定fileshare.readwrite,则仍应能够读取该文件:
1 | using (FileStream fs = new System.IO.FileStream("dict.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite) { |