Input/output: Exploring java.io
This chapter expl~res [ava.lo, which provides support for 1(0 oper?tions. In Chapter 12, we introduced Java’s I/O system. Here, we will exanune the java I/O system in greater detail.
As all programmers learn early on, most programs cannot accomplish their goals e: without accessing external data. Data is retrieved from an input source, The results of a program are sent to an output destination. In Java, these sources or destinations are defined very broadly. For example, a network connection, memory buffer, or disk file can be manipulated by the [ava 1/0 classes. Although physically different, these, devices are all handled by the same abstraction: the stream. A stream, as explained in . Chapter 12, is a logical entity that either produces or consumes information. A stream is linked to a physical device by the Java I/O system. All streams behave in the same manner, even if the actual physical devices they are linked to differ.
The ObjectInputStream.GetField and ObjectOutputStream.PutField inner classes were added by Java 2. TI1e[ava.lo package also contains classes that were deprecated ,by Java 2 and arc not shown in the preceding table: LineNumberInputStream and StringBufferInputStream. These classes should not be used for new code. The following interfaces are defined by java.io:
The Filcliiltcr interface was added by Java 2.
As you can see, there are many classes and interfaces in the java.io package. These include byte and character streams, and object serialization (the storage and retrieval of objects). This chapter examines several of the most commonly used I/O components, beginning wit~ one of the most unique: