Java I/O is a big issue and we will come back to it
often. There are several other classes and packates that we didn't
have time to discuss here. Some of these include:
-
-
RandomAccessFile
- Random access refers to writing and reading from a file starting
from any point in the file. We discuss this in the Chapter
9: Supplements section.
- Piped Streams - these are typically used to send data
from one thread to another. That is, instead of one thread copying
data to a buffer and the other thread reading from that buffer,
the piped stream classes provide a standard Java I/O stream framework
to connect the threads via a stream. See discussion with demo
in the Chapter
9: Supplements section.
-
Serial/Parallel Port I/O - discussed
in Chaper 23.
-
The Chapter 9: Tech section
uses histograms to illustrate several of the I/O techniques discussed
in this chapter. The topics include:
- Histogram I/O Overview
- Hist I/O with
Get/Set - uses getter methods to obtain the data for
saving the histogram to a file. Then read the data from a file
and use setter methods to fill the data fields in a new
Histogram
object.
- Hist I/O - Objects
- write and read Histogram
class objects.
- HistogramStream
- make Histogram
objects the destinations of streams.
- Filtering
Data - create stream filter classes to process data heading
to a Histogram
destination.
It can inially be confusing to find the correct type
of I/O classes to use for a particular kind of data. You can check
the tables here to find the starting class for your I/O task and
ways to wrap the class to add buffering,
filtering, and other useful methods:
Input Stream
Examples |
Source |
Stream Wrappings |
Console |
BufferedReader
(new InputStreamReader (System.in)) |
Text
in a byte stream |
BufferedReader
(new InputStreamReader (InputStream)) |
Text file |
BufferedReader
(new FileReader (new File ("f.txt")) |
Binary Data
File |
DataInputStream
(new FileInputStream (new File ("f.bin")) |
Output Stream
Examples |
Destination |
Stream Wrappings |
Console |
PrintWriter
(new OutputStreamWriter (System.out)) |
Text in a byte
stream |
PrintWriter
(new BufferedWriter (new OutputStreamWriter (OutputStream)))
|
TextFile |
PrintWriter
(new BufferedWriter ( new FileWriter (
new File ("f.txt"))) |
Binary Data
File |
DataOutputStream
(new FileOutputStream (new File ("f.bin")) |
Latest update: Nov. 14, 2004
|