我正在尝试将图像文件从beforePath移动到afterPath,以下是我的代码
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
public class ImageClass {
String fileName, beforePath, afterPath;
void moveFile() {
afterPath = afterPath + "\\" + fileName;
beforePath = beforePath + "\\" + fileName;
System.out.println(beforePath + " ,and, " + afterPath);
Path movefrom = FileSystems.getDefault().getPath(beforePath);
Path target = FileSystems.getDefault().getPath(afterPath);
try {
Files.move(movefrom, target, REPLACE_EXISTING);
} catch (IOException e) {
System.err.println(e);
}
}
}
然而代码返回java.nio.file.FileSystemException给我,它说另一个进程已经在使用该文件。我尝试了很多方法,但我做不到。我该如何解决?