使用以下代码将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);
答案 0 :(得分: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
就是如何打印任何对象 - 它与字节数组的内容没有直接关系。