File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to reassign standard input stream?" Watch "How to reassign standard input stream?" New topic
Author

How to reassign standard input stream?

Sam Kapoor
Greenhorn

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 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
 
 
subject: How to reassign standard input stream?