Here you can find the source of readBinaryFileAsFloats(String fileName)
private static float[] readBinaryFileAsFloats(String fileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; public class Main { private static float[] readBinaryFileAsFloats(String fileName) throws IOException { FileInputStream fis = new FileInputStream(new File(fileName)); byte data[] = readFully(fis); ByteBuffer bb = ByteBuffer.wrap(data); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); float result[] = new float[fb.capacity()]; fb.get(result);/*from w w w .ja va 2s .com*/ return result; } private static byte[] readFully(InputStream inputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte buffer[] = new byte[1024]; while (true) { int n = inputStream.read(buffer); if (n < 0) { break; } baos.write(buffer, 0, n); } byte data[] = baos.toByteArray(); return data; } }