我有两个网络方法。第一个是:
void deleteFile(string filePath)
{
File.Delete(filePath);
}
另一个是:
string[] getAllFile()
{
// at the same folder....
Directory.GetFiles("*.xml");
.....
return ....
}
我这样调用这些方法:
deleteFile("1.xml")
getAllFile();
尽管删除了“1.xml”文件,但调用Directory.GetFiles("*.xml");
结果中仍然返回“1.xml”。换句话说,它似乎没有被删除。
然后,当我循环结果时,尝试读取文件,得到 FileNotFoundException
我发现 DirectoryInfo/FileInfo 类并不总是更新。在这些情况下,您需要在目录/文件实例上调用 Refresh 方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)