You are here: Home / Topics / Program to read data from file using BufferedInputStream and display it on the monitor in Java

Program to read data from file using BufferedInputStream and display it on the monitor in Java

Filed under: Java on 2024-03-01 06:42:29

//  Program to read data from file using 
//  BufferedInputStream and display it on the monitor.

import java.io.*;

class  BufferedInputStreamDemo 
{
public static void main( String args[ ] ) throws IOException
{
 // attach the file to FileInputStream
 FileInputStream fis = new FileInputStream("file1.txt");
 BufferedInputStream bis = new BufferedInputStream( fis );
 
 System.out.println(" File contents are : ");
 // Read character from fis and write them to monitor.
 int ch;
 while( (ch=bis.read()) != -1 )
 {
  System.out.print( (char)ch );
 }
 
 // close the file
 fis.close();
}
}


Output:

 File contents are : 
 Java Programming Android Application

About Author:
G
Geetam     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.