java.io package -Jonathan Knudsen, Patrick Niemeyer
Input/Output Facilities :
The class hierarchy of the java.io package.
InputStream, OutputStream, Reader, and Writer classesInputStream/OutputStreamAbstract 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
InputStreamandOutputStream.Reader/WriterAbstract classes that define the basic functionality for reading or writing a sequence of character data, with support for Unicode. All other character streams in Java are built on top of
ReaderandWriter.InputStreamReader/OutputStreamWriter“Bridge” classes that convert bytes to characters and vice versa. Remember: in Unicode, a character is not a byte!
DataInputStream/DataOutputStreamSpecialized stream filters that add the ability to read and write simple data types, such as numeric primitives and
Stringobjects, in a universal format.ObjectInputStream/ObjectOutputStreamSpecialized stream filters that are capable of writing serialized Java objects and reconstructing them.
BufferedInputStream/BufferedOutputStream/BufferedReader/BufferedWriterSpecialized stream filters that add buffering for additional efficiency.
PrintWriterA specialized character stream that makes it simple to print text.
PipedInputStream/PipedOutputStream/PipedReader/PipedWriter“Double-ended” streams that normally occur in pairs. Data written into a
PipedOutputStreamorPipedWriteris read from its correspondingPipedInputStreamorPipedReader.FileInputStream/FileOutputStream/FileReader/FileWriterImplementations of
InputStream,OutputStream,Reader, andWriterthat read from and write to files on the local filesystem.
Streams in Java are one-way streets. The java.io input and output classes represent the ends of a simple stream, as shown in Figure 10.2. For bidirectional conversations, we use one of each type of stream.
InputStream and OutputStream are abstract classes that define the lowest-level interface for all byte streams. They contain methods for reading or writing an unstructured flow of byte-level data. Because these classes are abstract, you can’t create a generic input or output stream. Java implements subclasses of these for activities like reading from and writing to files and communicating with sockets. Because all byte streams inherit the structure of InputStream or OutputStream, the various kinds of byte streams can be used interchangeably. A method specifying an InputStream as an argument can, of course, accept any subclass of InputStream. Specialized types of streams can also be layered to provide features, such as buffering, filtering, or handling larger data types.Reader and Writer were added to thejava.io package. Reader and Writer are very much like InputStream and OutputStream, except that they deal with characters instead of bytes. As true character streams, these classes correctly handle Unicode characters, which was not always the case with the byte streams. However, some sort of bridge is needed between these character streams and the byte streams of physical devices like disks and networks. InputStreamReader and OutputStreamWriter are special classes that use an encoding scheme to translate between character and byte streams.

Comments
Post a Comment