No.
The bytes on the disk are just raw bytes. You (the programmer) have to know what you wrote in order to make sense of it. Here is another program:
import java.io.*; class TwoShorts { public static void main ( String[] args ) throws IOException { String fileName = "mixedTypes.dat" ; DataOutputStream dataOut = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( fileName ) ) ); dataOut.writeShort( 0 ); dataOut.writeShort( 0 ); dataOut.writeDouble( 12.45 ); dataOut.close(); } }
Two 16-bit shorts are written, each containing a zero.
The previous program wrote a 32-bit zero.
The double
is the same as before.
What will the output file look like?