CHAPTER 86 — Reading Binary Files



created: 06/20/00; revised 07/08/02

CHAPTER 86 — Reading Binary Files

Recall that binary files are those whose
bytes might hold any possible pattern.
Binary files store
data that has not been translated into character form.
Of course,
a binary file can store character data mixed in with its other data types.
A file that exclusively stores character data is
called a text file.

The subclasses of InputStream
are designed for byte-oriented input from any source.
For use, the source will usually be a file on the hard disk.
But other sources of data can also
be connected to a program as an InputStream.

Chapter Topics:

  • Reading binary files.
  • Advantages of binary files.
  • DataInputSteam
  • FileInputSteam
  • BufferedInputSteam
  • Reading and writing integers.
  • Reading and writing single bytes.

QUESTION 1:


While examining a hard drive
that you
found in a junk box
you find a mysterious file.
It looks like it might be a file of 32-bit integers.
Can you write a Java program to read it?