2

使用以下代码将 Flow_Rate 从“double”转换为字节数组,我收到了输出:[B@6a2b8b42

如何检查输出是否正确?

private double Flow_Rate= 8;   

OFVendor of_vendor = new OFVendor(); 
byte [] rate = ByteBuffer.allocate(8).putDouble(Flow_Rate).array(); 
of_vendor.setData(rate);  

Logger.stderr("ZB---->> ClientChannelWatcher::handleConnectedEvent OFVendor setData() : "+rate);
4

1 回答 1

1

我假设您的目标是将双精度的“位”放入二进制缓冲区。

如果是这样,您最好的选择可能是使用ByteBuffer

import java.nio.ByteBuffer;
...

private double Flow_Rate= 8.0; 
...

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

PS: [B@6a2b8b42这就是任何对象的打印方式-它与字节数组的内容没有直接关系。

于 2014-06-11T04:45:08.553 回答