Java InputStream Class

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

  1. FileInputStream
  2. ByteArrayInputStream
  3. ObjectInputStream

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


\begin{lstlisting}
// Creates an InputStream
InputStream object1 = new FileInputStream();
\end{lstlisting}

Here, we have created an input stream using FileInputStream. It is because InputStream is an abstract class. Hence we cannot create an object of InputStream.



Subsections