No. If the file does not open an
IOException is thrown and
then caught by
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 many bytes that encode fonts, page formats, and special symbols.
DataInputStream classes have
several methods for reading and writing single bytes.
Here are two of them:
DataOutputStream: public final void writeByte(int b) throws IOException DataInputStream: public final int readUnsignedByte() throws IOException
writeByte() writes the least significant byte
int argument to the output stream.
readUnsignedByte() reads a byte from the input
stream and puts it in the least significant byte of its
Could a byte read from a file by
be written to another file by