import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public boolean LoadBinaryData(String filename) throws IOException
{
boolean bRetVal = false;
FileInputStream fis = null;
DataInputStream dis = null;
try
{
File f = new File(filename);
if (f.isFile() && f.canRead())
{
fis = new FileInputStream(filename);
dis = new DataInputStream(fis);
// Bsp.: 8 Bytes als Double lesen
byte[] Test1 = new byte[8];
dis.read(Test1);
double a = ByteBuffer.wrap(Test1).order(ByteOrder.LITTLE_ENDIAN).getDouble();
System.out.println(a);
// Bsp.: 4 Bytes als Float lesen
byte[] Test2 = new byte[4];
dis.read(Test2);
float b = ByteBuffer.wrap(Test2).order(ByteOrder.LITTLE_ENDIAN).getFloat();
System.out.println(b);
// Bsp.: 2 Bytes als Short lesen
byte[] Test3 = new byte[2];
dis.read(Test3);
short c = ByteBuffer.wrap(Test3).order(ByteOrder.LITTLE_ENDIAN).getShort();
System.out.println(c);
bRetVal = true;
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (fis != null) fis.close();
if (dis != null) fos.close();
}
return bRetVal;
}