The throws
keyword indicates that a certain method can potentially "throw" a certain exception. You need to handle a possible IOException
(and possibly other exceptions) either with a try-catch
block or by adding throws IOException, (...)
to your method declaration. Something like this:
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) {...} ... */
}