我想将单个文件移动到另一个文件夹,但我不能,因为“它正在被另一个进程使用”。这是我的代码:
static File myFile = new File("C:\\filepath");
static File myFolder = new File("C:\\folderpath");
public static void main(String[] args)
throws IOException {
fileMove();
}
public static void fileMove()
throws IOException {
Files.move(myFile.toPath(), myFolder.toPath(), StandardCopyOption.REPLACE_EXISTING);
return;
}
错误消息:
线程“main”中的异常 java.nio.file.FileSystemException:C:\folderpath:该进程无法访问该文件,因为它正被另一个进程使用。
我尝试了不同的文件,不同的文件夹,但每次都说该文件正在被使用。我已经用一个基本的文本文件对其进行了测试,该文件在我测试它时肯定已关闭并且没有被使用,但我仍然得到错误。有谁知道发生了什么?或者,是否有另一种方法可以移动不会出现此问题的文件?