Reader and InputStream define similar APIs
but for different data types. For example, Reader contains
these methods for reading characters and arrays of characters:
int read()
int read(char cbuf[])
int read(char cbuf[], int offset, int length)
InputStream defines the same methods but for reading bytes
and arrays of bytes:
int read()
int read(byte cbuf[])
int read(byte cbuf[], int offset, int length)
Also, both Reader and InputStream provide
methods for marking a location in the stream, skipping input, and
resetting the current position.
Writer and OutputStream are similarly
parallel. Writer defines these methods for writing
characters and arrays of characters:
int write(int c)
int write(char cbuf[])
int write(char cbuf[], int offset, int length)
And OutputStream defines the same methods but for bytes:
int write(int c)
int write(byte cbuf[])
int write(byte cbuf[], int offset, int length)
All of the streams--readers, writers, input streams, and output
streams--are automatically opened when created. You can close any stream
explicitly by calling its close method.
Or the garbage collector can implicitly close it,
which occurs when the object is no longer referenced.