为什么我得到“未处理的异常类型IOException”? [英] Why do I get the "Unhandled exception type IOException"?
本文介绍了为什么我得到“未处理的异常类型IOException”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下简单代码:
import java.io.*;
class IO {
public static void main(String[] args) {
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
System.out.println(userInput);
}
}
}
我收到以下错误消息:
----------
1. ERROR in io.java (at line 10)
while ((userInput = stdIn.readLine()) != null) {
^^^^^^^^^^^^^^^^
Unhandled exception type IOException
----------
1 problem (1 error)roman@roman-laptop:~/work/java$ mcedit io.java
有人有什么想法吗?我只是想简化总和网站上提供的代码(这里)。我是否过度简化?
Does anybody have any ideas why? I just tried to simplify the code given on the sum web site (here). Did I oversimplify?
推荐答案
您应该在主方法中添加throws IOException:
You should add "throws IOException" to your main method:
public static void main(String [] args)抛出IOException {
你可以阅读更多关于 JLS 。
这篇关于为什么我得到“未处理的异常类型IOException”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文