CHAPTER 85 — Writing to Binary Files

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to home page   go to next page        

created: 06/15/2000; revised: 07/08/02, 06/09/03

CHAPTER 85 — 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 applications. However, this translation is not appropriate for non-character data. This chapter discusses OutputStream and its subclasses which are used for general-purpose output.

Chapter Topics:

  • Binary Files
  • OutputStream
  • FileOutputStream
  • BufferedOutputStream
  • DataOutputStream
    • writeInt()
    • writeDouble()
    • writeBytes()
  • Hexadecimal file dumps.

Most data types use all the bit patterns that can be formed with the eight bits of a byte. 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).

QUESTION 1:

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