Input Output Streams in Java
In this class, We discuss Input Output Streams in Java.
The reader should have proper basics on object-oriented concepts. Click Here.
Where are we getting the input data when we run the Java programs?
Sometimes we need to read the hard disc and network interface card data.
Java virtual machine JVM will handle the connections to input-output devices.
Whenever the JVM is on, it will create input and output streams.
The below diagram gives an idea of streams.
We need to read the data from the input and output streams to our program.
Which classes are used to do the reading and writing operations?
Two types of streams are available.
1) Byte stream
2) Character stream
Byte stream will read or write the data in the form of bytes.
Character stream will read or write the data in the form of characters.
The classes available in Java to read and write the byte streams are the inputstream and outputstream.
Similarly, the classes for character streams are reader and writer.
The above four classes are abstract.
The above class documentation is available on the oracle website.
The inputstream class is in java.io package.
The Java inbuilt packages provided many sub-classes to the super class inputstream.
Check the documentation for methods available in inputstream class.
Class x extends inputstream
{
int read()
{
}
}
We can not create an object for inputstream class. But we can create for class x.
In our last class, we discussed the concept of a superclass variable that can refer to subclass objects.
Inputstream ob = new x();
We are using the above concept.
The concept of a superclass variable can refer to a sub-class object used much in our next classes.