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();
Inten开发者_开发百科dedSoftwareVersion = input.readDouble();
DemoDays = input.readInt();
thanks in advance.
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.
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.
精彩评论