我尝试使用此问题中的示例:如何将文件夹及其所有子文件夹和文件复制到另一个文件夹中
我让他成为静态的,当我调用 copyDirectory() 时,我在程序运行期间出现异常:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
在使用此方法的每一行。
我添加了
throws IOException
对于每个使用 copyDirectory() 的方法
Error 的计数已被缩短,但它们仍保留在本地 java 类中。而且我无法编辑它们:这将是一个无限的编辑递归:))
提前我很抱歉英语不好。
UPD:(使用 ApacheCommonsIO)
import org.apache.commons.io.FileUtils;
// the rest import
public class MyClass{
public myMethod(){
String src = "/home/user/dir_src";
String dst = "/home/user/dir_dst";
FileUtils.copyDirectory(new File(src), new File(dst));
}
}