Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – The BufferedReader class

The BufferedReader is used to read text from a character input stream. It increases the performance.

Declaration

class BufferedReader extends Reader

Constructors for BufferedReader (CLICK HERE)

Methods defined in BufferedReader (CLICK HERE)

Note

The BufferedReader cannot create a connection with the file directly; therefore it needs to communicate with the help of Reader object.

Example

Let’s assume that text file “Hello.txt” is present in the current working dictionary.

Java Programming Language BufferedReader Class in File Handling

 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.IOException;

 class BufferedReaderDemo 
 {
     public static void main(String args[]) throws IOException
     {
         FileReader f = new FileReader("Hello.txt");
         BufferedReader br = new BufferedReader(f);
         String s = br.readLine();
         while(s!=null)
         {
             System.out.println(s);
             s = br.readLine();
         }
         br.close();
     }
 }

Output

Hello!
How are you?
I am fine...

 

Leave a reply