In this tutorial you will see how BufferReader Class is used to read the character at the command line.
In this tutorial you will see how BufferReader Class is used to read the character at the command line.Code:
import java.io.*;
class BufferedRead {
public static void main(String args[])
throws IOException {
char c;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nEnter character 'x' to quit");
do {
c = (char) br.read();
} while (c != 'x');
}
}
How to run this example:
c:\yourJavaFileDir>javac BufferedRead.java
c:\yourJavaFileDir>java BufferedRead
Enter character 'x' to quit
Type the text and to quit type x and press enter to exit