Unreported exception java.io.IOException when compiling Java code

霸气de小男生 提交于 2019-12-02 12:01:22

You need a try-catch block in your main method around all methods that throw an IOException:

try {
    printFile(gravity);
} catch (IOException ex) {
    // handle exception here
}

Include all methods that have throws IOException after the signature.

Change your main method declaration to:

public static void main(String[] args) throws IOException

In Java, each method A calling another method B, must declare all the exceptions
which B can throw (unless they are descendants of RuntimeException or unless A
is catching and processing them explicitly in a try-catch block).

In your case A is main, B is printFile.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!