import java.io.*;
class Tmp{
    public static void main(String btbbb[])throws IOException
              {BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));    String s =inp.readLine();       //输入字符串    System.out.println(s);        
    
              }
}
这是输入语句,我不明白为什么一定要抛出io异常,还是说有别的方式,能不抛出吗?

解决方案 »

  1.   

    因为readLine方法会产生IO异常,所以你必须对此异常进行处理,就是运行时会产生
    或者在你的方法里处理该异常
    如下
    try{
        String s =inp.readLine();       //输入字符串
    }catch(IOException e){
      System.out.println("可耻的出现异常:"+e.toString());     
    }这样你就可以不在你的main方法后面声明抛出IO异常了.
      

  2.   

    哦,有点问题,改这样    String s =null;
    try{
       s =inp.readLine();       //输入字符串
    }catch(IOException e){
      System.out.println("可耻的出现异常:"+e.toString());     
    }