Name: rm29839 Date: 09/18/97
import java.io.*;
// Program to demo BufferedReader problem
// Eventually readLine() fails to recognize the Enter key being pressed
// It can take some time although it can be quite quick.
// It seems to be randome but maybe it depends on whats in the buffer
// It is not repeatable - the same input does not necessarily fail.
public class TestBufferedReader
{
//***************************************************************************
// main()
//***************************************************************************
public static void main(String[] args)
{
BufferedReader kb = new BufferedReader(
new InputStreamReader(System.in));
String text = " ";
try
{
while (text.length() != 0)
{
System.out.print("Enter some text - empty line to end: ");
text = kb.readLine().trim();
System.out.println("\n Text length = "+text.length());
}
} // end try
catch (Exception e)
{
System.out.println(e);
} // end catch Exception
} // end main()
}
Sample output - you can see where the end of input was not recognized:
Enter some text - empty line to end: eeeeeeeee
Text length = 9
Enter some text - empty line to end: fffffff
Text length = 7
Enter some text - empty line to end: fffffffff
Text length = 9
Enter some text - empty line to end: bbbbbbbbb
Text length = 9
Enter some text - empty line to end: vvvvvvvv
Text length = 8
Enter some text - empty line to end: cccccc
yyyyyyyyyy
yyyyyy
yyy
yyyyyyyyy
yyyyy
yyyyyy
yyyyyyyy
yyyyyy
yyyyyyyyy
Text length = 6
Enter some text - empty line to end:
Text length = 10
Enter some text - empty line to end:
Text length = 6
Enter some text - empty line to end:
Text length = 3
Enter some text - empty line to end:
Text length = 9
Enter some text - empty line to end:
Text length = 5
Enter some text - empty line to end:
Text length = 6
Enter some text - empty line to end:
Text length = 8
Enter some text - empty line to end:
Text length = 6
Enter some text - empty line to end:
Text length = 9
Enter some text - empty line to end:
Text length = 0
company - n/a , email - ###@###.###
======================================================================