Java OutputStream Class

The OutputStream class of the java.io package is an abstract superclass that represents an output stream of bytes. Since OutputStream is an abstract class, it is not useful by itself. However, its subclasses can be used to write data. In order to use the functionality of OutputStream, we can use its subclasses. Some of them are:

  1. FileOutputStream
  2. ByteArrayOutputStream
  3. ObjectOutputStream

In order to create an OutputStream, we must import the java.io.OutputStream package first. Once we import the package, here is how we can create the output stream.


\begin{lstlisting}
// Creates an OutputStream
OutputStream object = new FileOutputStream();
\end{lstlisting}

Here, we have created an object of output stream using FileOutputStream. It is because OutputStream is an abstract class, so we cannot create an object of OutputStream.