by Dinesh Thakur

To read a character form the Buffered Reader object, use the following version of read() method. int read( ) throws IOException

The method read() will return a integer value corresponding the character from the input stream and if end of the stream come across then it will return -1.

 

Example: To read characters.

 

import java.io.*;

class CharacterRead

{

public static void main(String args[]) throws IOException

{

char ch;

BufferedReader brObj = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter characters, 'Q' to quit.");

do

{

ch = (char) brObj.read();

System.out.println(ch);

} while(ch != 'Q');

}

}

 

Output:

 

Character Reader