Introduction to I/O STREAMS in JAVA

In computer science Streams are defined as the sequence of data elements that is made available over time. It represents a Source( which generates the data in the form of Stream) and a destination( which consumes or read data available as Stream). In other simple words it is a flow of data from which you can read or write data to it.

These Streams have no concept of indexing like we have in Arrays neither we can move forward or backward in them rather you can consider them like a conveyer belt on which you can feed the item sequentially or you can pick the item sequentially.

In Streams you can process the data one at a time as bulk operations are unavailable with them. Streams supports a huge range of source and destinations including disk file, arrays, other devices, other programs etc.

Streams- reading Data from a stream
Streams- reading Data from a stream
Streams- inserting Data into the stream
Streams- inserting Data into the stream

To make a stream active we have to use some objects so as to pull data from a stream or push data into the stream.

Pull Vs Push Stream

  • Pull Streams are used to pull data or to retrieve data from the Stream. Java provides a lot of pull stream all we have to do is to use them by creating an object of them and using read() method.
    Example :- Reader, InputStream
  • Push Streams are used to push data or to insert data into the Stream. Java provides a lot of push stream all we have to do is to use them by creating an object of them and using write() method.
    Example :- Reader, InputStream

Basic Streams in JAVA

Java defines two types of streams. They are-

  • Byte Streams :- These are the most basic type of Stream for input output operations and are used to process data byte by byte. Byte based streams generally end up calling by word “Stream” like InputStream and OutputStream and are used to process a raw Byte at a time.
    Some Exceptions are DataInputStream and DataOutputStream which are used to read and write Java standard datatypes like int, long, float and double.
  • Character Streams :- These provide a convenient way for handling character inputs and output. These can be used for internationalization purpose as Character Streams uses UNICODE characters.
    These streams end up calling by a word “Reader” or “Writer” like InputStreamReader, FileReader, OutputStreamWriter, FileWriter etc.

Keep Learning 🙂

Recommended -

Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Jalak Patel
Jalak Patel
7 years ago

Its great and in simple lang….TY…

Hitesh Garg
7 years ago
Reply to  Jalak Patel

Thank you, such comments keeps us motivated.

Would love your thoughts, please comment.x