Javatpoint Logo
Javatpoint Logo

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 Type Field Description
protected Object lock The object used to synchronize operations on this stream.

Constructor

Modifier Constructor Description
protected Reader() It creates a new character-stream reader whose critical sections will synchronize on the reader itself.
protected Reader(Object lock) It creates a new character-stream reader whose critical sections will synchronize on the given object.

Methods

Modifier and Type Method Description
abstract void close() It closes the stream and releases any system resources associated with it.
void mark(int readAheadLimit) It marks the present position in the stream.
boolean markSupported() It tells whether this stream supports the mark() operation.
int read() It reads a single character.
int read(char[] cbuf) It reads characters into an array.
abstract int read(char[] cbuf, int off, int len) It reads characters into a portion of an array.
int read(CharBuffer target) It attempts to read characters into the specified character buffer.
boolean ready() It tells whether this stream is ready to be read.
void reset() It resets the stream.
long skip(long n) It skips characters.

Example

file.txt:

I love my country

Output:

I love my country




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA