For reading console input in Java, a character stream is created by wrapping System.in in a BufferedReader object. Following constructor is used:
To get InputStreamReader object, which is linked to System.in, the below given constructor is used:
To create a BufferedReader connected to keyboard:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
where, br is a character based stream linked to System.in
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, boolean flushn)
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.