Java programming language has many classes to read input characters. One such class is BufferedReader class and this program demonstrate the BufferedReader class in Java.
We are using JDK 8u111 with Netbean IDE 8.2 installed on a Windows 7 64-bit PC to compile and run this program. You can also install the JDK and run this program from a windows command console.
This program use the BufferedReader class to create a new BufferedReader object. The main program is BRRead and the Java program is saved with the same name – BRRead.java. To write a program to read character using Bufferedreader class in Java and display the characters in integer equivalent.
For example, if character is ‘a’, then output is 97 – ANSI equivalent.
The BufferedReader object uses InputStreamReader another object from InputStreamReader Class that reads a stream of characters.
public static void main(String args)
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
System.out.println("Enter character,'10' to quit");
// read characters
}while(c != 10);
Output – BufferedReader Demo
The output of the above program is given below. The program reads a stream of character through BufferedReader object and display the characters when the last read character is 10.
Enter character,'10' to quit