Read File Using BufferedInputStream - Java File Path IO

Java examples for File Path IO:BufferedInputStream

Description

Read File Using BufferedInputStream

Demo Code


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Main {
  public static void main(String[] args) {
    File file = new File("C://Folder//ReadFile.txt");
    BufferedInputStream bin = null;

    try {/*w w  w  .ja  va 2  s.co  m*/
      FileInputStream fin = new FileInputStream(file);
      bin = new BufferedInputStream(fin);
      while (bin.available() > 0) {
        System.out.print((char) bin.read());
      }
    } catch (FileNotFoundException e) {
      System.out.println("File not found" + e);
    } catch (IOException ioe) {
      System.out.println("Exception while reading the file " + ioe);
    } finally {
      try {
        if (bin != null)
          bin.close();

      } catch (IOException ioe) {
        System.out.println("Error while closing the stream : " + ioe);
      }

    }
  }

}

Result


Related Tutorials