created: 06/15/2000; revised: 07/08/02, 06/09/03, 09/01/11, 10/13/2017

go to home page   go to next page

CHAPTER 104 — Writing to Binary Files

The character-oriented streams (Readers and Writers) translate data between an internal 16-bit format and an external UTF format. This is convenient for many text processing applications. However, this translation is not appropriate for non-character data. This chapter discusses OutputStream and its subclasses which are used for binary output. They do not translate the data from what is on the disk to what is delivered to your program.

Most data types represent data using all the possible patterns that can be formed from their bits. A file that contains such data is often called a binary file. A byte from a binary file might hold any possible pattern. (A byte from an ASCII text file is restricted to somewhat less than half of the possible patterns).

Recall (from chapter 2!) the four advantages of binary:

  1. Binary devices are Simple and easy to build.
  2. Binary signals are Unambiguous (which gives them noise immunity).
  3. Flawless copies can be made of binary data.
  4. Anything that can be represented with some sort of pattern can be represented with patterns of bits.

Because of the fourth advantage, anything that can be represented with some sort of pattern can be represented with pattrns of bits in a disk file. You need I/O methods that read and write these patterns without change.

Chapter Topics:


QUESTION 1:

(Review: ) How many patterns can be formed using 8 bits?


go to home page   go to next page