Read console input, Write console output, write method, PrintWriter class in Java

For reading console input in Java, a character stream is created by wrapping in a BufferedReader object. Following constructor is used:

BufferedReader(Reader inputReader)

To get InputStreamReader object, which is linked to, the below given constructor is used:

InputStreamReader(InputStream inputStream)

To create a BufferedReader connected to keyboard:

BufferedReader br = new BufferedReader(new InputStreamReader(;

where, br is a character based stream linked to

Write console output: print( ) and println( ) methods are used for console output in Java.These methods are in PrintStream class which is derived from OutputStream. Also, write method is used to write to console.

write method: It is used to write to console.


void write(int bytevalue)

PrintWriter class: PrintWriter is also used to write to console. Constructors defined by PrintWriter class:

PrintWriter(OutputStream ostream)

PrintWriter(OutputStream ostream, boolean flushn)

PrintWriter(Writer ostream)

PrintWriter(Writer ostream, boolean flushn)

where, ostream is an object of type OutputStream.

and flushn is used to control flushing of output stream when println( ) method is called. If flushn is true then, flushing is automatic, otherwise it is not.

Leave a Reply