BufferedReader read Example

BufferedReader class read example. This example shows you how to use read method.


BufferedReader class read example. public int read(char[] cbuf, int off, int len) throws IOException This method implements the general contract of the corresponding read method of the Reader class. As an additional convenience, it attempts to read as many characters as possible by repeatedly invoking the read method of the underlying stream.

Here is the code
/*
 * @ # Read.java
 * A class repersenting use to read method 
 * of BufferedReader class in java.io package
 * version 29 May 2008
 * author Rose India 
 */

import java.io.*;

public class Read1 {

    public static void main(String[] argsthrows Exception {

        // 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()];
        bufReader.read(arr, 0, arr.length - 14);
        System.out.println(arr);

        // Close the BufferedReader object and the underlying
        // StringReader object.
        stringReader.close();
        bufReader.close();
    }
}

Output
This is the internal String

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US