No.
You could make some shrewd guesses about what the data of some files represent. For example, it is easy to recognize a text file because every byte represents a character (or control character), and the characters will be grouped into words that make sense. It would be an amazing coincidence if that happened for a file of integer data.
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 program then writes the same double
as before.
What will the output file look like?