Java IOException - Stream Closed

前端 未结 2 1405
心在旅途
心在旅途 2021-01-19 12:12

I get \"IOException: Stream Closed\" when I run this program. The text contains many lines of data. Program should read each line, do necessary functio

2条回答
  •  隐瞒了意图╮
    2021-01-19 13:06

    You should put a function call in the while loop, like:

    1. a System.out.println("Hi, I'm a row!"); or
    2. uncomment System.out.println(inputLine); or
    3. put a semicolon at the end of the while statement

    in order to let it to execute properly.

    The code as it is written executes (comments omitted):

    ...
       while ((inputLine = in.readLine()) != null)
         in.close();  
    ...
    

    so the first cycle of the loop executes correctly and runs in.close(). Then the second cycle the call inputLine = in.readLine() fails because the stream is closed and then the exception is thrown.

提交回复
热议问题