I am writing a double value in Java into a file like below,
byte[] bytes = new byte[8];
//Double d = new Double(4);
double d =1000;
ByteBuffer.wrap(bytes).putDouble(d);
File test = new File(FILE_PATH+"readme.bin");
test.createNewFile();
FileOutputStream ostream = new FileOutputStream(test);
ostream.write(bytes);
ostream.close();
and I can read it back in with Java code, but when retrieving it in C code I get the value as 0.000000
. My C code is as follows,
FILE *file_ptr;
file_ptr = fopen(file_absolute,"rb");
if (!file_ptr)
{
printf("Unable to open file!");
return 1;
}
char bytes[8];
fread(&bytes, 8, 1, file_ptr);
double d = *((double*)bytes);
printf("%f",d);
Am I missing anything here? Both C and Java code are running on the same system.