Friday, 3 February 2017

I/O STREAMS IN JAVA

Stream is a logical connection between java program and a file. Stream can be defined as “a continuous flow of data between java program and persistence media”.

Types of streams – Generally streams are divided into two types based on data flow direction.
InputStream – The stream that allows data to come into the java application from the persistent media is called input stream.
OutputStream – The stream that allows data to send out from the java application to be stored into the persistent media and outputstreams are used to write or store data in persistent media from a java application.

Types of java streams –
In java we are allowed to send data through streams only, either in the format of bytes or characters. Hence, based on the type of the data passed, streams are divided into two types. They are –
1. BinaryStream – The streams which read and write data in the format of bytes is called binary streams.
2. CharacterStream – The streams which read and write data in the format of characters is called character streams

What are the different sources and destinations to read and write data?
The sources can be a keyboard, mouse, file, database, socket, object, array, String, StringBuffer. The destinations can be a monitor, file, database, socket, object, array, String,StringBuffer.

InputStream and OutputStream class hierarchy –
For each type of source and destination java.io package has given a separate class. Following diagram shows InputStream and OutputStream classes hierarchy –






No comments:

Post a Comment