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.
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.
Introduction to I/O STREAMS in JAVA was last modified: October 14th, 2014 by Hitesh Garg
Thanks for reading this post. If you feel it to be worthy and helpful then don't hesitate in sharing this knowledge with the world. Don't you think it is a great idea to connect with us so that we can keep you updated. Google Plus Facebook LinkedIn Twitter Reddit