Java Reader Class

Category: Java   Tags: Java, Java File Handling, Java Character Stream Class, Java Reader Class

Reader is an abstract class. It defines how Java streams character input. It has below declaration:

                                    public abstract class Reader
                                    extends Object
                                    implements Readable, Closeable
                                

Constructors

protected Reader()
Creates a new character-stream reader. Its critical sections will synchronize on the reader itself.
protected Reader(Object obj)
Creates a new character-stream reader. Its critical sections will synchronize on the given object obj

Methods

public int read(CharBuffer buffer) throws IOException
Read characters into the specified character buffer and returns the actual number of characters that were successfully read. Returns –1 if the end of the file is encountered.
public int read() throws IOException
Returns an integer representation of the next available character from the invoking input stream. Returns -1 if the end of the stream is reached.
public int read(char buffer[]) throws IOException
Read up to buffer.length characters into buffer and returns the actual number of characters that were successfully read. Returns -1 if the end of the stream is reached.
public int read(char[] c, int offset, int num) throws IOException
It tries to read characters (up to num character) into c starting at c[offset] and returns the actual number of character that were successfully read. Returns -1 if the end of the file is reached.
public long skip(long n) throws IOException
It skips n characters of input, returning the number of characters actually ignored.
public void mark(int n)
Marks the current position in this input stream that will remain valid until n characters are read.
public void reset()
Resets the input pointer to the previously set mark.
public boolean ready() throws IOException
Indicate whether this stream is ready to be read. Returns true if the next read() is guaranteed not to block for input, false otherwise.
public abstract void close() throws IOException
Closes the stream and releases any system resources associated with the stream. Further read attempts will generate an IOException.