10.4 Basic Binary-File I/O
The White Rabbit put on his spectacles. “Where shall I begin, please your Majesty?” he asked.
“Begin at the beginning,” the King said, very gravely, “And go on till you come to the end: then stop.”
—LEWIS CARROLL, Alice's Adventures in Wonderland
We will use the stream classes ObjectInputStream and ObjectOutputStream to read and write binary files. Each of these classes has methods to read or write data one byte at a time. These streams can also convert numbers and characters to bytes that can be stored in a binary file. They allow your program to be written as if the data placed in the file, or read from the file, were made up not just of bytes but of either items of any of Java’s primitive data types—such as int ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access