Skip to main content
 首页 » 编程设计

c#之错误 "An unhandled exception of type ' System.IO.IOException' 出现在 mscorlib.dll 中”

2024年02月13日14lidabo

我收到以下错误:

An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file because it is being used by another process.

来自以下代码行:

Directory.Move(location, newLocation); 

其中 location 和 newLocation 是定义的字符串。

在此之前,我使用了以下 I/O 方法:

String[] directories = Directory.GetDirectories(location); 
String[] files = Directory.GetFiles(location); 
Directory.Exists(location); 

位置字符串与当前给我错误的行中的位置字符串相同。

然后我继续使用数组中的目录和文件,但从不打开文件。

我需要对 getDirectories 和 getFiles 应用类似关闭的东西,还是我的问题出在其他地方?

请您参考如下方法:

我自己发现了问题。我尝试将该目录移动到其自身的子目录,这当然不起作用。