No. If the file does not open an IOException
is thrown and
then caught by
the outer catch{}
block
Usually data is much more complicated than the data for the example program. But the program shows the outer logic that is needed to read most files. Sometimes the data in a file represents something other than a primitive Java type. For example, word processor files contain various arrangements of bytes that encode fonts, page formats, special symbols, and graphics.
The DataOutputStream
and DataInputStream
classes have
several methods for reading and writing single bytes.
writeByte()
writes the least significant byte
of its int
argument to the output stream.
readUnsignedByte()
reads a byte from the input
stream and puts it in the least significant byte of its
return value.
DataOutputStream: public final void writeByte(int b) throws IOException DataInputStream: public final int readUnsignedByte() throws IOException
Could a byte read from a file by readUnsignedByte()
be written to another file by writeByte()
.