The Reader class

The methods of the class are deliberately similar to the methods of the class. However rather than working with bytes, they work with chars. The basic read() method reads a single character (which may may take between one and four bytes depending on the character set) and returns the character as an int between 0 and 65535. It returns -1 if the end of stream is seen.

 public int read() throws IOException

You can also read many characters into an array of chars. These methods return the number of bytes successfully read or -1 if the end of stream occurs.

 public int read(char[] text) throws IOException
 public abstract int read(char[] text, int offset, int length) 
  throws IOException

All the read() methods block until some input is available, an I/O error occurs, or the end of the stream is reached.

You can skip a certain number of characters. This method also blocks until some characters are available. It returns the number of characters skipped or -1 if the end of stream is reached.

 public long skip(long n) throws IOException

The ready() method returns true if the reader is ready to be read from, false if it isn't. Generally this means the underlying stream has available data.

 public boolean ready() throws IOException

Readers may or may not support marking and resetting, like input streams.

 public boolean markSupported()
 public void mark(int readAheadLimit) throws IOException
 public void reset() throws IOException

Finally the close() method closes the Reader and releases any resources associated with it.

 public abstract void close() throws IOException

Copyright 2000 Elliotte Rusty Harold
Last Modified January 29, 2000