This question already has an answer here:
- How can I fix an “IOException: Stream closed” exception using System.in? 1 answer
In my code I have to read user input from console:
class Demo {
//...some code
public String readUserInput() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String userInput = reader.readLine();
reader.close();
return userInput;
}
}
On first time when I use method readUserInput()
on Demo object everything is OK. But when I create another Demo object and call method - it throws Exception with the message
"Stream closed"
Can anybody tell me, why I have Exception on different not equal objects? Thank you for your attention.