Java Reader

Java Reader is an abstract class for reading character streams. The only methods that a subclass must implement are read(char[], int, int) and close(). Most subclasses, however, will override some of the methods to provide higher efficiency, additional functionality, or both.

Some of the implementation class are BufferedReader, CharArrayReader, FilterReader, InputStreamReader, PipedReader, StringReader

Fields

Modifier and TypeFieldDescription
protected ObjectlockThe object used to synchronize operations on this stream.

Constructor

ModifierConstructorDescription
protectedReader()It creates a new character-stream reader whose critical sections will synchronize on the reader itself.
protectedReader(Object lock)It creates a new character-stream reader whose critical sections will synchronize on the given object.

Methods

Modifier and TypeMethodDescription
abstract voidclose()It closes the stream and releases any system resources associated with it.
voidmark(int readAheadLimit)It marks the present position in the stream.
booleanmarkSupported()It tells whether this stream supports the mark() operation.
intread()It reads a single character.
intread(char[] cbuf)It reads characters into an array.
abstract intread(char[] cbuf, int off, int len)It reads characters into a portion of an array.
intread(CharBuffer target)It attempts to read characters into the specified character buffer.
booleanready()It tells whether this stream is ready to be read.
voidreset()It resets the stream.
longskip(long n)It skips characters.

Example

file.txt:

I love my country

Output:

I love my country




Latest Courses