Java I/O Streams Tutorial - Part 1

We all know stream is a sequence of data, input and output streams represent the input sources and the output destination. These sources can include memory arrays, programs or devices. The data which we send also categorized into the objects, simple bytes, primitive data types, characters or multimedia types.

Java Development Kit provides APIs for reading and writing streams of data. We can find them in package. For reading the data Java opens a stream to a data source such as a file or remote socket and on other side for writing it again opens stream and write serially.

Now lets see the types of streams :

Byte Stream :

Bytestreams deals with byte data type. Programs use byte streams for input and output of 8 bit bytes. The classes which support bytestream are InputStream and OutputStream.

Character Stream:

As the name suggest character streams deals with characters having Unicode conventions. Character streams are supported by and and their subclasses. Character streams are less complicated than byte streams and more powerful which directly translates the format to and from using the local character set. Character streams have lot of advantages such as they can handle any character in Unicode character set. Character streams are not dependent on specific character set for encoding , they quickly adapt the local character set so it becomes very easy to internationalize. Also the buffering techniques also makes them efficient than byte streams , so unless we need to input or output any binary data such as image or sound files we can use character streams.

Buffered Stream :

In the above two streams, reading and writing request being taken care at underlying OS which makes them somehow less efficient. To decrease the overhead , JDK gives the buffered stream APIs .
The memory area which is used for reading and writing operation is called as buffer. Program can convert unbuffered stream to buffered stream by passing unbuffered stream to the constructor of buffered stream class. To wrap unbuffered byte stream to the buffered byte stream classes used are BufferedInputStream and BufferedOutputStream and for character stream buffering BufferedReader and BufferedWriter classes are used.
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment


  1. Tha'ts going to make things a lot easier from here on out.