Stream I/O Classes


InputStream/OutputStream

Abstract classes that define the basic functionality for reading or writing an unstructured sequence of bytes. All other byte streams in Java are built on top of the basic InputStream and OutputStream.

Reader/Writer

Abstract classes that define the basic functionality for reading or writing an unstructured sequence of characters. All other character streams in Java are built on top of Reader and Writer.

InputStreamReader/OutputStreamWriter

Bridge classes that convert bytes to characters and characters to bytes. An InputStreamReader is a character stream that gets its input from a byte stream. An OutputStreamWriter is a character stream that sends its output to an underlying byte stream. An encoding scheme is responsible for translating between bytes and unicode characters. An InputStreamReader or OutputStreamWriter can be created to use the default encoding scheme for the host system, or to use some other specified encoding scheme.

DataInputStream/DataOutputStream

Specialized stream filters that add the ability to read and write primitive types and String objects from/to an underlying stream. They provide methods (readInt(), writeInt(), readDouble(), writeDouble(), etc.) to read or write primitive types. These methods read or write data in binary format, not in human-readable form. DataInputStream provides a readLine() method that can be used to read a String, but if you want to read characters you should use the readLine() method of BufferedReader instead.

ObjectInputStream/ObjectOutputStream

Specialized stream filters that are capable of writing serialized Java objects and reading and reconstructing them.

BufferedInputStream/BufferedOutputStream

Specialized streams that add buffering for additional efficiency. They provide methods for reading/writing a byte or an array of bytes.

BufferedReader/BufferedWriter

Specialized streams that add buffering for additional efficiency. They provide methods for reading/writing a char or an array of chars. BufferedReader also provides the readLine() method for reading an input line into a String.

PrintStream

A stream that provides methods to write string representations of primitive types, Strings, and Objects (using the object’s toString() method) to an underlying output stream. PrintStream handles unicode using the host system’s default encoding. As of JDK 1.1 you should use PrintWriter instead.

PrintWriter

A stream that provides methods to write string representations of primitive types, Strings, and Objects (using the object’s toString() method) to an underlying output stream. PrintStream handles unicode using the host system’s default encoding.

PipedInputStream/PipedOutputStream/PipedReader/PipedWriter

"Double-ended" streams that always occur in pairs. Piped streams are used for communication between threads. Data written into a PipedOutputStream or PipedWriter by one thread is read from its corresponding PipedInputStream or PipedReader by the other thread.

FileInputStream/FileOutputStream

Byte streams that read from/write to files on the local filesystem. These classes provide methods to read or write bytes. Wrap these with a DataInputStream or DataOutputStream if you need to read or write primitive types or Strings.

FileReader/FileWriter

Character streams that read from/write to files on the local filesystem. These classes provide methods to read or write characters. Wrap a FileReader with a BufferedReader for efficiency, and also to obtain a readLine() method to read a line.

ByteArrayInputStream/ByteArrayOutputStream

Streams that read from and write to an array of bytes. They provide methods to read or write a byte or an array of bytes.

CharArrayReader/CharArrayWriter

Streams that read from and write to an array of characters. They provide methods to read or write a char or an array of chars.

StringReader/StringWriter

Character streams that read from and write to a String (similar to CharArrayReader/CharArrayWriter). They provide methods to read or write a char or an array of chars.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page