另外,什么是throws NumberFormatException, IOException
意思是?我一直在尝试使用BufferedReader
通过说
BufferedReader nerd = new BufferedReader(new InputStreamReader(System.in));
but BufferedReader
不会起作用,除非throws NumberFormatException, IOException
被放入。
The throws
关键字指示某个方法可能会“抛出”某个异常。你需要处理一个可能的情况IOException
(可能还有其他例外)或者带有try-catch
块或通过添加throws IOException, (...)
到你的方法声明。像这样的事情:
public void foo() throws IOException /* , AnotherException, ... */ {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
in.readLine();
// etc.
in.close();
}
public void foo() {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
in.readLine();
// etc.
in.close();
} catch (IOException e) {
// handle the exception
} /* catch (AnotherException e1) {...} ... */
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)