*
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
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
 
Consider Paul's rocket mass heater.
 
subject: How to reassign standard input stream?
 
Similar Threads
how to IO console through MyApplication?
Getting input with instructor code isn't working as I would expect...
Program Stoping for some reason
Add Method Question
Scanner question about hasNext() and next()