Prev | Current Page 229 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"


One other situation calls for the use of InputStream/OutputStream classes, too. That is when one
does not care what the data represent. This would be the case, for example, when the task is to copy a file. The
program doing the copying does not need to know what the content of the file means; it just needs to copy
each byte to a new file. In that case, using the InputStream/OutputStream classes instead of the
Reader/Writer classes makes sense, even if the file to be copied consists of characters, because the
InputStream/OutputStream classes will be more efficient??”the step of translating bit patterns to characters
will be skipped.
88 PROGRAMMING IN JAVA [CHAP. 5
There are 50 classes in java.io, and we will describe only a few here. To read a file of character data,
one would use a BufferedReader ???wrapped around??? a FileReader. The Java I/O design is very flexible,
and this is a good example of that. A FileReader reads characters from a file, and by wrapping the
FileReader with a BufferedReader, the I/O will be accomplished more efficiently by reading a group
of characters at once. The BufferedReader also provides a method called readLine(), which allows the
program to read a whole line at a time from a file into a String variable.


Pages:
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
stretching exercises grow taller studia podyplomowe logistyka teksty piosenek Ustawy Nr8 świnoujście