Java defines two types of streams:
Byte streams are used to handle input and output of bytes. For example, reading or writing binary data.
Character streams are used to handle input and output of characters. They use Unicode and can be internationalized.
Byte streams are defined by using two class hierarchies.
At the top are two abstract classes:
The following table lists several stream classes.
Stream Class | Meaning |
---|---|
BufferedInputStream | Buffered input stream |
BufferedOutputStream | Buffered output stream |
ByteArrayInputStream | reads from a byte array |
ByteArrayOutputStream | writes to a byte array |
DataInputStream | contains methods for reading the Java standard data types |
DataOutputStream | contains methods for writing the Java standard data types |
FileInputStream | reads from a file |
FileOutputStream | writes to a file |
FilterInputStream | Implements InputStream |
FilterOutputStream | Implements OutputStream |
InputStream | Abstract class that describes stream input |
ObjectInputStream | for objects |
ObjectOutputStream | for objects |
OutputStream | Abstract class that describes stream output |
PipedInputStream | Input pipe |
PipedOutputStream | Output pipe |
PrintStream | Output stream that contains print() and println() |
PushbackInputStream | supports one-byte "unget," which returns a byte to the input stream |
SequenceInputStream | a combination of two or more input streams that will be read sequentially, one after the other |
Character streams are defined by using two class hierarchies: Reader and Writer.
These abstract classes handle Unicode character streams.
Java has several concrete subclasses of each of these.
Stream Class | Meaning |
---|---|
BufferedReader | Buffered input character stream |
BufferedWriter | Buffered output character stream |
CharArrayReader | Input stream that reads from a character array |
CharArrayWriter | Output stream that writes to a character array |
FileReader | Input stream that reads from a file |
FileWriter | Output stream that writes to a file |
FilterReader | Filtered reader |
FilterWriter | Filtered writer |
InputStreamReader | Input stream that translates bytes to characters |
LineNumberReader | Input stream that counts lines |
OutputStreamWriter | Output stream that translates characters to bytes |
PipedReader | Input pipe |
PipedWriter | Output pipe |
PrintWriter | Output stream that contains print() and println() |
PushbackReader | Input stream that allows characters to be returned to the input stream |
Reader | Abstract class that describes character stream input |
StringReader | Input stream that reads from a string |
StringWriter | Output stream that writes to a string |
Writer | Abstract class that describes character stream output |