Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

The java.io Package - Overview

  • the package contains three main groups of classes and interfaces
    1. classes to build data streams
    2. classes and interfaces for serialization
    3. classes and interfaces for working with the file system

Data Streams (JCL1)

  • data streams that read values from a data source are input streams
  • data streams that write values to a data repository are output streams
  • the data can be either byte or character values
DataStream SuperClasses
Byte Streams Character Streams
abstract class InputStream abstract class Reader
abstract class OutputStream abstract class Writer
  • there are two classes which convert bytes to characters
        class InputStreamReader extends Reader
        class OutputStreamWriter extends Writer
    
  • data containers, for example files, usually provide methods which return a stream for either reading or writing
  • data streams can be chained together

Filter Streams

  • filter streams perform some processing or filtering as the data is passed through
  • a filter ouput stream performs the processing before the data is written out
  • a filter input stream performs the processing after the data is read from its original source
FilterStream SuperClasses
Byte Streams Character Streams
class FilterInputStream class FilterReader
class FilterOutputStream class FilterWriter
  • there are number of filter streams for both byte streams
        BufferedInputStream                 BufferedOutputStream
        DataInputStream                     DataOutputStream
        LineNumberInputStream               PrintStream
        PushbackInputStream
    
  • and character streams
        BufferedReader                      PrintWriter
        LineNumberReader
        PushbackReader
    

In-Memory Streams

  • there are also classes for reading and writing data held in memory
        ByteArrayInputStream                CharArrayReader
        ByteArrayOutputStream               CharArrayWriter
                                            StringReader     
                                            StringWriter
    
  • the StringReader/Writer classes read data from a StringBuffer object

Pipes

  • there are classes that allow you to build streams that operate between threads
        PipedInputStream                    PipedReader
        PipedOutputStream                   PipedWriter
    

Files

  • there are a number of classes for working with the file system
        File                                
        FileDescriptor                      
        
        FileInputStream                     FileReader
        FileOutputStream                    FileWriter
        FilenameFilter
        FilePermission                      RandomAccessFile
    
  • note that File, FileDescriptor and RandomAccessFile are direct subclasses of Object
Note
The File class can be used to create directories

Serialization (JCL1)

  • serialization is the process of converting an object to a stream of bytes in such a manner that the original object can be rebuilt (lets you write an object to a file or other data container)


Pkg Overview Data Streams Character Streams Byte Streams File Class Readers & Writers
Filter Streams Data Input/Output Reading & Writing Files Serialization