Yes.
A Java int
uses patterns of 32 bits to represent integers.
The exact pattern contained in an int
can be written to four bytes
of a binary file.
OutputStream
is an abstract class from which all
byte-oriented output streams descend.
Its descendant classes are used for binary output.
These streams
write groups of bytes to output destinations.
A FileOutputStream
connects an output stream of bytes to a file.
It is has methods for writing single bytes or an array of bytes to a file,
and some other methods.
These methods are not very useful for us since you have to deal with
the individual bytes of a data type.
A DataOuputStream
can be connected to a FileOutputStream
to write groups of bytes to a stream.
Use DataOuputStream
to send data of spectific types to a stream, and use
FileOutputStream
to send that stream to a disk file.
(See the example program on the next page.)
Does FileOutputStream
itself provide a way to write an int
to a disk?
Does DataOutputStream
provide a way to write an int
to a stream?