如何确保字节数组已从double数据类型转换数据

时间:2014-06-12 01:16:50

标签: java arrays double bytebuffer

我正在获取输出

[B@3a2fc571

byte[] rate = new byte[8];
ByteBuffer.wrap(rate).putDouble(Flow_Rate);

我用这个函数来写这个数据 of_vendor.setData(rate); 但是当函数接受byte[]的数组时,容量是相同的并且在使用函数之后不写入该字节。 将其转换为ByteBuffer后,输出相同,输出为

java.nio.HeapByteBuffer[pos=0 lim=0 cap=8]

1 个答案:

答案 0 :(得分:-1)

wrap是ByteBuffer的静态方法并返回ByteBuffer的新实例,你必须捕获实例然后操作它,尝试这样的事情:

byte[] rate = new byte[8];
ByteBuffer obj = ByteBuffer.wrap(rate)
obj.putDouble(Flow_Rate);
...
return obj