Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to reassign standard input stream?

 
Sam Kapoor
Greenhorn
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 System.in 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 System.in by calling
System.setIn(System.in);

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?

Thanks:

-Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic