Java IO Introduction

Reading assignment

Basic introduction from Java tutorial

Basic points

Here are some basic points about I/O:

Overview of I/O Streams

Refer to Sun's Java tutorial.
Overview of I/O Streams

To bring in information, a program opens a stream on an information source (a file, memory, a socket) and reads the information sequentially, as shown here:

Similarly, a program can send information to an external destination by opening a stream to a destination and writing the information out sequentially, like this:

No matter where the data is coming from or going to and no matter what its type, the algorithms for sequentially reading and writing data are basically the same:
ReadingWriting
open a stream
while more information
    read information
close the stream
open a stream
while more information
    write information
close the stream
The java.io package contains a collection of stream classes that support these algorithms for reading and writing. To use these classes, a program needs to import the java.io package. The stream classes are divided into two class hierarchies, based on the data type (either characters or bytes) on which they operate

InputStream/OutputStream vs Reader/Writer

IOException

Understanding the I/O Superclasses

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.

What to use ?

A table of classes from Java tutorial : Using the Streams .