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
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();
You should put a function call in the while loop, like:
System.out.println("Hi, I'm a row!");
orSystem.out.println(inputLine);
orin 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.