Java FileInputStream : Byte Streams

Java program uses byte stream to perform the different input and output operations on the bytes. Java byte stream classes are descendant of InputStream and OutputStream.

Java FileInputStream : Byte Streams

  1. FileInputStream obtains the input bytes from the file.
  2. The class is used to get input bytes from a file
  3. FileInputStream is usually used for reading streams of raw bytes such as image data


Program : Java FileInputStream – Byte Streams

package com.examples.basic;


class ReadFile {
  public static void main(String args[]) {
    try {
      FileInputStream fin = new 
      int i;
      while ((i = != -1)
        System.out.print((char) i + " ");


    } catch (Exception e) {

Output :

J a v a   i s   O O P   L a n g u a g e . 

Explanation :

In the above example, we need to create one text file called input.txt whose content is like this –

Java is OOP Language.

Now we need to place this file such that we can have correct relative path –

Package Structure InputStreamReader

We must give relative path by taking src as root folder. Otherwise we will get following error – input.txt 
         (The system cannot find the file specified)

In the next tutorial we will be learning the FileOutputStream.