【发布时间】:2012-10-06 17:37:32
【问题描述】:
我尝试使用这个问题的例子:How to copy a folder and all its subfolders and files into another folder
我将他设为静态,当我调用 copyDirectory() 时,程序运行时出现异常:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
在使用此方法的每一行。
我加了
throws IOException
对于每个使用 copyDirectory() 的方法
错误的计数已被缩短,但它们仍保留在本地 java 类中。而且我无法编辑它们:这将是一个无限的编辑递归:))
Advance 我很抱歉英语不好。
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));
}
}
【问题讨论】:
-
它是一个编译时错误,所以首先尝试解决编译时错误然后去寻找异常
-
是的,我使用 vim + eclim 插件。我没有“红线”和编译问题。
-
您解决了编译时间错误吗?
-
我通过在每个使用 copyDirectory() 的方法中添加“抛出 IOException”来解决它们。是错误的方式,但不知道如何纠正它们。
-
你能发布你的代码吗?您必须处理代码中某处引发的异常
标签: java static directory ioexception