writeDouble()
Here is a very short program that writes a few doubles to a file.
import java.io.*; class WriteDoubles { public static void main ( String[] args ) throws IOException { String fileName = "doubleData.dat" ; DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( fileName ) ) ); out.writeDouble( 0.0 ); out.writeDouble( 1.0 ); out.writeDouble( 255.0 ); out.writeDouble( -1.0 ); out.close(); } }
Primitive type double
uses 64 bits, or eight bytes per value.
The hex dump of "doubleData.dat" shows four groups of eight bytes.
The first group is recognizable as zero, but the others are mysterious.
Floating point data are represented with different bit patterns
than integer data.
The right side of each line in the dump attempts to interpret the bytes as ASCII characters. The "." means the byte can't be a character. Some bytes happen to contain a pattern that could be a character. One byte could represent the character "@" and the one after it could represent "o".