The Character Streams

The Character Streams include direct I/O support for characters. At the top of the character stream hierarchies are the Reader and Writer abstract classes.

Reader

Reader is an abstract class that defines Java's model of streaming character input.

It implements the Closeable and Readable interfaces.

Methods from Reader

abstract void close( )
Closes the input source.
void mark(int numChars)
Places a mark at the current point that will remain valid until numChars characters are read.
boolean markSupported( )
Returns true if mark( )/reset( ) are supported.
int read( )
Returns an integer representation of the next available character. -1 is returned when the end of the file is encountered.
int read(char buffer[ ])
Reads up to buffer.length characters into buffer and returns the actual number of characters that were successfully read. -1 is returned when the end of the file is encountered.
abstract int read(char buffer[ ], int offset, int numChars)
Reads up to numChars characters into buffer starting at buffer[offset], returning the number of characters successfully read. -1 is returned when the end of the file is encountered.
boolean ready( )
Returns true if the next input request is ready.
void reset( )
Resets the input pointer to the previously set mark.
long skip(long numChars)
Skips numChars characters of input, returning the number of characters actually skipped.

Writer

Writer is an abstract class that defines streaming character output. It implements the Closeable, Flushable, and Appendable interfaces.

Methods from Writer

Writer append(char ch)
Writes ch to the writer.
Writer append(CharSequence chars)
Writes chars to the end.
Writer append(CharSequence chars, int begin, int end)
Writes the subrange of chars specified by begin and end-1.
abstract void close( )
Closes the output stream.
abstract void flush( )
Flushes the output buffers.
void write(int ch)
Writes a single character to the output stream.
void write(char buffer[ ])
Writes a complete array of characters to the output stream.
abstract void write(char buffer[ ], int offset, int numChars)
Writes a subrange of numChars characters from the array buffer, beginning at buffer[offset] to the invoking output stream.
void write(String str)
Writes str to the invoking output stream.
void write(String str, int offset, int numChars)
Writes a subrange of numChars characters from the string str, beginning at the specified offset.
Home 
  Java Book 
    File Stream  

Introduction:
  1. The Stream Classes
  2. The Byte Streams
  3. The Character Streams
  4. NIO