Java Basic I O Overview - RameshMF/java-io-guide GitHub Wiki
Java I/O Guide focuses on I/O Streams, a powerful concept that greatly simplifies I/O operations. This guide also looks at serialization, which lets a program write whole objects out to streams and read them back again. Then the lesson looks at file I/O and file system operations, including random access files.
Most of the classes covered in the I/O Streams section are in the java.io package. Most of the classes covered in the File I/O section are in the java.nio.file package.
- Byte Streams
- Character Streams
- Buffered Streams
- Data Streams
- Object Streams
I/O Streams An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays.
Streams support many different kinds of data, including simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data; others manipulate and transform the data in useful ways.
No matter how they work internally, all streams present the same simple model to programs that use them: A stream is a sequence of data. A program uses an input stream to read data from a source, one item at a time:
Reading information into a program. Reading information into a program.
A program uses an output stream to write data to a destination, one item at time:
Writing information from a program. Writing information from a program.
Java application uses an output stream to write data to a destination, it may be a file, an array, peripheral device or socket.
Java application uses an input stream to read data from a source, it may be a file, an array, peripheral device or socket.
Java IO contains many subclasses of the InputStream, OutputStream, Reader and Writer classes. The reason is, that all of these subclasses are addressing various different purposes. That is why there are so many different classes. The purposes addressed are summarized below:
- File Access
- Network Access
- Internal Memory Buffer Access
- Inter-Thread Communication (Pipes)
- Buffering
- Filtering
- Parsing
- Reading and Writing Text (Readers / Writers)
- Reading and Writing Primitive Data (long, int etc.)
- Reading and Writing Objects
diagram here
diagram
InputStream Hierarchy diagram
Byte Based | Character Based | |||
Input | Output | Input | Output | |
Basic | InputStream | OutputStream | Reader InputStreamReader |
Writer OutputStreamWriter |
Arrays | ByteArrayInputStream | ByteArrayOutputStream | CharArrayReader | CharArrayWriter |
Files | FileInputStream RandomAccessFile |
FileOutputStream RandomAccessFile |
FileReader | FileWriter |
Pipes | PipedInputStream | PipedOutputStream | PipedReader | PipedWriter |
Buffering | BufferedInputStream | BufferedOutputStream | BufferedReader | BufferedWriter |
Filtering | FilterInputStream | FilterOutputStream | FilterReader | FilterWriter |
Parsing | PushbackInputStream StreamTokenizer |
PushbackReader LineNumberReader |
||
Strings | StringReader | StringWriter | ||
Data | DataInputStream | DataOutputStream | ||
Data - Formatted | PrintStream | PrintWriter | ||
Objects | ObjectInputStream | ObjectOutputStream | ||
Utilities | SequenceInputStream |