简体   繁体   中英

java read a byte stream of float number

Not familiar with java IO. Here is the question: a byte stream which contains a series of float number between -1 and 1. How should I read the input?

I've tried this:

BufferedReader br=new BufferedReader(new ByteInputStream(buf, length));

but get no idea.

Thanks.

You could read a float from a buffer like this:

try(DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf, 0, len))){
    // ...
    float v = dis.readFloat();
    // ...
}

BufferedReader is not needed as this one would read from a buffer.

If your floats are coming from ie C++ application, you could read integers and use Float.intBitsToFloat() to convert them to Java floats: Best way to serialize a Float in java to be read by C++ app?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM