I was wondering why I get a java.io.IOException: Stream closed
error when using
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
In 2 different classes.
The setup is as follows.
public class SomeClass{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//br.readSomeStuff
br.close();
new SomeOtherClass(); //defo not passing the br along to the new class!
}
public class SomeOtherClass{
public SomeOtherClass(){
method():
}
private void method(){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
br.readLine();
// results into an IOEXCEPTION Stream close
}
}
The issue is gone when I close the BufferedReader in the first class AFTER the creation of the other class. I dont understand why this would give issues though. I am creating a new BufferedReader on System.in, why could this possibly result into a stream closed error?
Similar question here. Does not explain WHY System.in is closed for some reason though.
Thanks in advance!