FileInputStream and FileOutputStream in java

In the previous post, We have seen FileReader which is used to read the data from text file. In this post, we will look at FileInputStream and FileOutputStream in java. These classes are used to read and write the data to a file i.e. used for file handling.

Let’s look at them with example.


It is used to write the data as a stream of bytes into a file. The FileOutputStream class is a subclass of OutputStream meaning you can use a FileOutputStream as an OutputStream.

For writing character oriented data, we can use FileWriter.

Example of FileOutputStream:

Output: Write tasks successful.


It reads the content of File as a stream of bytes. It is a subclass of InputStream. For reading the stream of characters, we use FileReader class.

It can be used to read byte-oriented data for example to read image, audio, video etc.

Example of FileInputStream:

Output: I am making a painting.
Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum


FileReader in java
BufferedInputStream and BufferedOutputStream in java
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

1 Response

  1. August 8, 2015

    […] the previous post, we have seen FileInputStream and FileOutputStream. In this post, we will look at BufferedInputStream and BufferedOutputStream in […]