java readLine()为什么会错误呢?
来源:百度知道 编辑:UC知道 时间:2024/05/09 16:55:54
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class revenue {
public static void main(String[] args)
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String inputLine=in.readLine();
}
}
错误信息:
revenue.java:10: unreported exception java.io.IOException; must be caught or declared to be thrown
String inputLine=in.readLine();
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class revenue {
public static void main(String[] args)
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String inputLine=in.readLine();
}
}
错误信息:
revenue.java:10: unreported exception java.io.IOException; must be caught or declared to be thrown
String inputLine=in.readLine();
readLine();会抛出异常,你要处理一下
1.try...catch
2.public static void main(String[] args)throws Exception
readLine();会抛出异常。
正确的写法是:
try{
String inputLine=in.readLine();
}
catch(IOException ex)
{
}
I/O异常必须对其进行捕捉或声明以便抛出
可以用try-catch 或 throws IOException
意思好像是要你考虑异常,或者用try/catch
try{
String inputLine=in.readLine();
}
catch(IOException ex){}