我可以用try-catch循环“修复”下面的异常,但我无法理解原因.
>为什么“in.readLine()”部分会连续点燃IOExceptions?@H_502_3@>抛出此类异常的目的是什么,目标可能不仅仅是更多的副作用?
代码和IOExceptions
$javac ReadLineTest.java ReadLineTest.java:9: unreported exception java.io.IOException; must be caught or declared to be thrown while((s=in.readLine())!=null){ ^ 1 error $cat ReadLineTest.java import java.io.*; import java.util.*; public class ReadLineTest { public static void main(String[] args) { String s; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // WHY IOException here? while((s=in.readLine())!=null){ System.out.println(s); } } }