小编use*_*553的帖子

Java编译器抱怨未报告的IOException

我正在尝试编写一个列出目录中所有非隐藏文件的方法.但是,当我添加条件时,!Files.isHidden(filePath)我的代码将无法编译,并且编译器返回以下错误:

java.lang.RuntimeException: Uncompilable source code - unreported exception 
java.io.IOException; must be caught or declared to be thrown
Run Code Online (Sandbox Code Playgroud)

我试图赶上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(); 
}
Run Code Online (Sandbox Code Playgroud)

java file-io exception-handling ioexception java-8

3
推荐指数
1
解决办法
218
查看次数

标签 统计

exception-handling ×1

file-io ×1

ioexception ×1

java ×1

java-8 ×1