Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to reassign standard input stream?  RSS feed

Sam Kapoor
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i have a problem where i need to prompt the user to enter data into the console window (1 line) and read from the console. I wrap the in a BufferedReader like this:
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String inputStr = br.readLine();
while (inputStr != null){
//read from console

Now the problem is that if the user hits CTRL + Z (on Windows) the InputStream becomes null.

Further down in the method I need to once again prompt the user to enter data in the Console but this time invoking the bufferedReader.readLine() always returns null (and does not even block).

The JavaDocs say that this method returns null once end of stream has been reached.

I tried re-setting the by calling

but that does not give me what I am looking for.

Any ideas on how I can get to read from the console once CTRL+Z has been entered?


Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!