sajjoo
sajjoo

Reputation: 6614

Facing problem from getting double and int value from binary file

Can anybody please tell me how to get double and int value from a binary file. I have tried alot but its giving me wrong values. Here is my code.

InputStream iStream = getApplicationContext().getResources().openRawResource(R.raw.map);

    DataInputStream input;

        input = new DataInputStream(iStream);   

            try {                   

double mapFileFormatVersionNumber, IntendedSoftwareVersion;         
int DemoDays;

mapFileFormatVersionNumber =input.readDouble();                     
IntendedSoftwareVersion = input.readDouble();
DemoDays = input.readInt();

thanks in advance.

Upvotes: 0

Views: 524

Answers (2)

user405725
user405725

Reputation:

There is no difference in C++ and Java integer types. They are both signed 32-bit numeric types. However, its binary representation might be different depending on the byte order. For example, integer might be represented in file in little endian byte order and reading it assuming it is in big endian will result in wrong data. You might want to experiment with byte order if you don't know exactly how it is stored in the file. Take a look at ByteBuffer Java class, it supports different byte orders.

Upvotes: 0

sfussenegger
sfussenegger

Reputation: 36095

Tthere are a gazillion possible representations of integers and doubles. Hence you simply can't expect DataInputStream to be compatible with whatever bizarre binary format. You'll have to go through the specs of .AMF file format and roll your own conversion.

Upvotes: 1

Related Questions