Chapter 10: Using I/O

1. Why does Java define both byte and character streams?

The byte streams are the original streams defined by Java. They are especially useful for binary I/O, and they support random-access files. The character streams are optimized for Unicode.

2. Even though console input and output is text-based, why does Java still use byte streams for this purpose?

The predefined streams, System.in, System.out, and System.err, were defined before Java added the character streams.

3. Show how to open a file for reading bytes.

Here is one way to open a file for byte input:

Image

4. Show how to open a file for reading characters.

Here is one ...

Get Java, A Beginner's Guide, 5th Edition, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.