Name: rm29839 Date: 11/17/97
I am using a command line interface to prompt the
user for input; so I'm alternating outputing text and
reading text. I'm using a BufferedReader for
capturing input and I've tried various output
streams (System.out, PrintWriter, System.err)
Problem: If the user types their text and hits
'Enter' too quickly the next output prompt is not
written to the screen until all io in that
function is completed.
If the user types their
text and waits (about at least 3/4 second) and then
hits 'Enter' the following output prompt is
written to the screen as expected.
In other words, if my user types as fast as I
usually do they won't be prompted for input.
If they type in the data anyways, the BufferedReader
does still read the data just fine. And all the
text I sent to System.out is finally written
when the function exits.
Here is some sample code:
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print("Building: ");
System.out.flush();
building = br.readLine();
System.out.print("Floor: ");
System.out.flush();
floor = br.readLine();
System.out.print("Type (a or i): ");
System.out.flush();
type = br.readLine();
tCheckOut(building, floor, type);
This code works fine on WinNT, and Solaris, it only exhibits the skipped output on Win95
import java.io.*;
public class test {
public static void main (String[] args){
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String floor, type, building;
try {
System.out.print("Building: ");
System.out.flush();
building = br.readLine();
System.out.print("Floor: ");
System.out.flush();
floor = br.readLine();
System.out.print("Type (a or i): ");
System.out.flush();
type = br.readLine();
System.out.println(building + floor + type);
}catch(IOException e){};
}
}
(Review ID: 19745)
======================================================================