by Dinesh Thakur

When a program is executed, the input is read from the various sources and the output is sent to different destinations. Generally, keyboard and monitor screen are used as standard input and output device, respectively.


The data fed by the user is supplied to the program using input streams and the output of the program is supplied to the output device using output streams. This output is displayed to the user using Java PrintStream class. So far the two methods, print () and println (),that have been used for displaying the primitive data type, object, etc. on an output device are defined by the PrintStream class. This is a byte stream class which is derived from the Output Stream class. Unlike other output streams, the PrintStream class does not throw an IOException even if an exceptional event occurs.

PrintStream class can be connected to the underlying output stream such as

FileOutputStream, ByteArrayOutputStream, BufferedOutputStream, etc

Print Stream class defines following type of constructor.

PrintStream(OutputStream os)

This constructor creates a print stream and connects it to the output stream os.

In addition to print () and println () methods, the PrintStream class defines some Other methods which are listed in Table

                                        Table PrintStream Class Methods



PrintStream append (char c)

Appends the character c to the output stream

PrintStream append (CharSequence cs)

Appends the character sequence c to the output stream

boolean checkError ()

Checks the error state of the stream

protected void setError ()

Sets the error state to true