Read 4-Byte floating binary file with java | SoloLearn: Learn to code for FREE!


Read 4-Byte floating binary file with java

I searched on the internet, I find just sthg related to read/write binary file int, short, byte but not for float. Having a square matrix 100*100 stored as floating values as binary file, I would read its value in order to e.g. store them in 2D float array etc... Any help plz

12/19/2018 4:10:40 PM


1 Answer

New Answer


In Java a char is 16-bit. If you mean you have a 4 byte values in little endian byte order which you need to convert to a float you can use ByteBuffer. byte[] bytes = { } float f = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getFloat();