When I try to write binaries to a file with a value like this:
public static main(String[] args){ ByteBuffer output = ByteBuffer.allocate(80); output.order(ByteOrder.BIG_ENDIAN); output.putDouble(545.5); appendByteArrayInFile("c:/myPath/", "test.bin", output.array()); } private static void appendByteArrayInFile(String exportDirectory, String fileName, byte[] toAppendInFile) { if (toAppendInFile != null) { File targetExport = createPathAndFile(exportDirectory + fileName); try (FileOutputStream output = new FileOutputStream(targetExport, true)) { output.write(toAppendInFile); } catch (Exception e) {
The fact is that when I look at the generated file, it seems that the double is placed in a little endian style, and when I switch ByteOrder to little-endian, double is written in big-endian ... But when I put the int, the validity is correct.
BigEndian double exit:
01000000 10000001 00001100 00000000 00000000 00000000 00000000 00000000
Double exit in littleEndian:
00000000 00000000 00000000 00000000 00000000 00001100 10000001 01000000
Exit with int in bigEndian:
00000000 00000000 00000010 00100001
source share