by Dinesh Thakur Category: Stream

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


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, 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