+ 1

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

19th Dec 2018, 4:10 PM
Khaled
Khaled - avatar
1 Réponse
+ 6
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(); https://stackoverflow.com/questions/13469681/how-to-convert-4-bytes-array-to-float-in-java
8th Jan 2019, 2:25 AM
Kiyoshi G Yoshida 🇧🇷
Kiyoshi G Yoshida 🇧🇷 - avatar