为什么我会得到“未处理的异常类型 IOException"? [英] Why do I get the "Unhandled exception type IOException"?

查看:53
本文介绍了为什么我会得到“未处理的异常类型 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 

有人知道为什么吗?我只是试图简化 sum 网站上给出的代码(here).我是否过于简单化了?

Does anybody have any ideas why? I just tried to simplify the code given on the sum web site (here). Did I oversimplify?

推荐答案

您应该在 main 方法中添加throws IOException":

You should add "throws IOException" to your main method:

public static void main(String[] args) 抛出 IOException {

您可以在 JLS.

这篇关于为什么我会得到“未处理的异常类型 IOException"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆