Java IOException - Stream Closed

前端 未结 2 1409
心在旅途
心在旅途 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 12:59

    You close the input stream in your loop:

    while ((inputLine = in.readLine()) != null) // error
    
                   // System.out.println(inputLine);
    in.close();  
    

    You should close the stream outside of the loop:

    while ((inputLine = in.readLine()) != null) // error
    {
       //dosomething
       // System.out.println(inputLine);
    }
    in.close();  
    

提交回复
热议问题