import java.io.*;
class StandardIn1
{
public static void main(String[] args) throws IOException
{
char c;
System.out.println(" 输入一个字符:");
c=(char)System.in.read();
System.out.println(" 输入的字符是:"+c);
}
}上面的程序运行没有问题,请问各位同仁,程序中为什么需要 throws IOException ,书上的解释是 程序中使用了 System.in.read(),使用了 read() 就要throws IOException ,我不理解,请各位指点。
若程序去掉 throws IOException ,编译就会报错。
class StandardIn1
{
public static void main(String[] args) throws IOException
{
char c;
System.out.println(" 输入一个字符:");
c=(char)System.in.read();
System.out.println(" 输入的字符是:"+c);
}
}上面的程序运行没有问题,请问各位同仁,程序中为什么需要 throws IOException ,书上的解释是 程序中使用了 System.in.read(),使用了 read() 就要throws IOException ,我不理解,请各位指点。
若程序去掉 throws IOException ,编译就会报错。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货