import java.io.File;
import org.openqa.selenium.io.FileHandler;
public class Test1 {
public static void main(String[] args)throws Exception
{
FileHandler.copy(new File("C:\\Users\\Desktop\\Abc"), new File("C:\\Users\\Desktop\\Abc2"));
}
}
当路径有效时,上面的代码可以正常工作,但是当路径无效或文件不存在时,它不会抛出任何 IO 异常。
我在 intellij 和 eclipse 中运行了上面的代码,但是当我用 java.io 做同样的事情时看不到任何错误,它抛出错误。
最佳答案
这似乎是预期的行为,正如 API 所示,如下 -
public static void copy(File from, File to) throws IOException {
if (!from.exists()) {
return;
}
if (from.isDirectory()) {
copyDir(from, to);
} else {
copyFile(from, to);
}
}
因此,如果文件不存在,它就会返回。
if (!from.exists()) {
return;
}
关于java - 即使文件不存在,selenium 中的文件处理程序方法也不会抛出任何 IO 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42329616/