Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
BufferedReader Class
Collapse the table of content
Expand the table of content

BufferedReader Class

Visual Studio 2005

Provides an implementation of the abstract Reader class that buffers character data from another reader.

Package: java.io

Assembly: vjslib (in vjslib.dll)


public class java.io.BufferedReader
    extends java.io.Reader

The following example demonstrates the close, mark, markSupported, read, ready, and reset methods of the BufferedReader class.

// bufferedreader_overview.jsl

import java.io.*;

public class Program
{
    public static void main(String[] args)
    {
        try
        {
            // Create a new instance of a BufferedReader object using
            // a StringReader.
            String s = "This is the internal StringReader buffer.";
            StringReader stringReader = new StringReader(s);
            BufferedReader bufReader = new BufferedReader(stringReader);

            // Read from the underlying StringReader.
            char[] arr = new char[s.length()];
            if (bufReader.ready())
            {
                bufReader.read(arr, 0, arr.length - 10);
            }

            // Call mark after having read all but the last 10
            // characters from the StringReader.
            if (bufReader.markSupported())
            {
                bufReader.mark(s.length());
            }

            // Read the rest of the data from the underlying
            // StringReader.
            if (bufReader.ready())
            {
                bufReader.read(arr, arr.length - 10, 10);
            }
            System.out.println(arr);

            // Call reset and then re-read from the underlying
            // StringReader.
            bufReader.reset();
            char[] arr2 = new char[s.length()];
            bufReader.read(arr2);
            System.out.println(arr2);

            // Close the BufferedReader object and the underlying
            // StringReader object.
            stringReader.close();
            bufReader.close();
        }
        catch (IOException ex)
        {
            System.out.println(ex.toString());
        }
    }
}

/*
Output:
This is the internal StringReader buffer.
er buffer.
*/

The BufferedReader class provides functionality to read characters from a stream with buffering. It also provides mark and reset functionality for reading characters back and forth within a buffered limit from a sequential stream.

java.lang.Object

   java.io.Reader

    java.io.BufferedReader

       java.io.LineNumberReader

Community Additions

ADD
Show:
© 2015 Microsoft