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中做同样的事情时,我看不到任何错误,它抛出了错误。
发布于 2017-02-20 01:11:12
这似乎是一个预期的行为,正如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;
}https://stackoverflow.com/questions/42329616
复制相似问题