This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes How to reassign standard input stream? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to reassign standard input stream?" Watch "How to reassign standard input stream?" New topic

How to reassign standard input stream?

Sam Kapoor

Joined: Jul 24, 2003
Posts: 1
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?


I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: How to reassign standard input stream?
It's not a secret anymore!