BufferedReader class in java

java.io.BufferedReader is a class in java programming language. Inside of this class exists 10 public methods. Declaration of this class as follows.

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

BufferedReader public method

There are following useful methods which is define the inside of java.io.BufferedReader class.

void close() It closes the stream and releases any system resources associated with it.
Stream lines() It returns a, the elements of which are lines read from this BufferedReader.
void mark(int readAheadLimit) It marks the present position in the stream.
boolean markSupported() It tells whether this stream supports the mark() operation, which it does.
int read() It reads a single character.
int read(char[] cbuf, int off, int len) It reads characters into a portion of an array.
String readLine() It reads a line of text.
boolean ready() It tells whether this stream is ready to be read.
void reset() It resets the stream to the most recent mark.
long skip(long n) It skips characters.

This reference is belong to javadoc

Public Constructors

public java.io.BufferedReader(java.io.Reader,int)
public java.io.BufferedReader(java.io.Reader)
// BufferedReader Constructors Example
import java.io.FileReader;
import java.io.BufferedReader;
class Example
	public static void main(String[] args)
			// data1.txt,data2 is file in current directory
			FileReader f1 = new FileReader("data1.txt");
			FileReader f2 = new FileReader("data2.txt");
			BufferedReader r1 = new BufferedReader(f1);
			BufferedReader r2 = new BufferedReader(f2);
			int info;
			System.out.print("r1 read : ");
			// Read file data1.text
			while ((info = r1.read()) != -1)
				// print info
				System.out.print((char) info);
			System.out.print("\nr2 read : ");
			// Read file data2.text
			while ((info = r2.read()) != -1)
				// print info
				System.out.print((char) info);
		catch (Exception e)
bufferedreader class instance A bufferedreader class instance B
r1 read : We Love
r2 read : Coding Problem


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment

© 2022, kalkicode.com, All rights reserved