The Wayback Machine - https://web.archive.org/web/20200219201050/https://www.geeksforgeeks.org/java-io-bufferedreader-class-java/amp/

Java.io.BufferedReader Class in Java

Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.

Constructors:

Methods:



filter_none

edit
close

play_arrow

link
brightness_4
code

//Java program demonstrating BufferedReader methods
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class BufferedReaderDemo
{
    public static void main(String[] args) throws IOException 
    {
        FileReader fr = new FileReader("file.txt");
        BufferedReader br = new BufferedReader(fr);
        char c[]=new char[20];
  
        //illustrating markSupported() method
        if(br.markSupported())
        {
            System.out.println("mark() method is supported");
              
            //illustrating mark method
            br.mark(100);
        }
          
        /*File Contents
        * This is first line
        this is second line
        */
          
        //skipping 8 characters
        br.skip(8);
  
        //illustrating ready() method
        if(br.ready())
        {
            //illustrating readLine() method
            System.out.println(br.readLine());
  
            //illustrating read(char c[],int off,int len)
            br.read(c);
            for (int i = 0; i <20 ; i++)
            {
                System.out.print(c[i]);
            }
            System.out.println();
  
            //illustrating reset() method
            br.reset();
            for (int i = 0; i <8 ; i++) 
            {
                //illustrating read() method
                System.out.print((char)br.read());
            }
        }
    }
}
chevron_right

Output :

mark() method is supported
first line
this is second line
This is 

This article is contributed by Nishant Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



Article Tags :
Practice Tags :