by Dinesh Thakur Category: Stream

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





About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles