Android : Android ByteBuffer to float conversation return wrong values

on Tuesday, September 16, 2014


I am trying to read txt file using RandomAccessFile and FileChannel which contains large number of float / integer values, but at after the all conversations using ByteBuffer the values which I get as a result are not the same with the ones in txt file. Here is how I am doing it :



RandomAccessFile mRandomFile = new RandomAccessFile(Environment.getExternalStorageDirectory() + "/Models/vertices.txt", "rw");
FileChannel mInChannel = mRandomFile.getChannel();
ByteBuffer mBuffer = ByteBuffer.allocate(181017 * 4);
mBuffer.clear();

mInChannel.read(mBuffer);

mBuffer.rewind();
FloatBuffer mFloatBUffer = mBuffer.asFloatBuffer();
mFloatBUffer.get(VERTS);

mInChannel.close();

for (int i = 0; i < 20; i++) {
Log.d("", "VALUE: " + VERTS[i]);
}


The values in txt file are presented in this way (they are separated with a new line):



-36.122300
-6.356030
-46.876744
-36.122303
-7.448818
-46.876756
-36.122303
-7.448818
81.123221
-36.122300
-6.356030
81.123209
36.817676
-6.356030
-46.876779
36.817676
-7.448818
-46.876779
-36.122303
-7.448818


and the values which I am getting in for are:



VALUE: 1.0187002E-11
VALUE: 2.5930944E-9
VALUE: 6.404289E-10
VALUE: 2.5957827E-6
VALUE: 2.6255839E-6
VALUE: 8.339467E-33
VALUE: 4.1885793E-11
VALUE: 1.0740952E-5
VALUE: 1.0187002E-11
VALUE: 2.5930944E-9
VALUE: 6.513428E-10
VALUE: 1.0383363E-5
VALUE: 4.3914857E-5
VALUE: 8.339467E-33
VALUE: 4.1885793E-11
VALUE: 1.0801023E-5
VALUE: 1.0187002E-11
VALUE: 2.5930944E-9
VALUE: 6.513428E-10
VALUE: 1.0383363E-5


Any ideas, suggestions what I am missing here?


0 comments:

Post a Comment