【发布时间】:2015-08-16 11:32:07
【问题描述】:
我正在尝试编写一个列出目录中所有非隐藏文件的方法。但是,当我添加条件!Files.isHidden(filePath) 时,我的代码将无法编译,并且编译器返回以下错误:
java.lang.RuntimeException: Uncompilable source code - unreported exception
java.io.IOException; must be caught or declared to be thrown
我试图捕捉IOException,但编译器仍然拒绝编译我的代码。我错过了什么明显的东西吗?代码如下。
try {
Files.walk(Paths.get(root)).forEach(filePath -> {
if (Files.isRegularFile(filePath) && !Files.isHidden(filePath)) {
System.out.println(filePath);
} });
} catch(IOException ex) {
ex.printStackTrace();
} catch(Exception ex) {
ex.printStackTrace();
}
【问题讨论】:
-
@the compiler 仍然拒绝编译我的代码" - 是同样的错误还是不同的错误?
-
@mikej 出现同样的错误
-
您可以尝试这里列出的方法:stackoverflow.com/questions/31270759/…
标签: java file-io exception-handling java-8 ioexception