Java如何从收到的UDP字节解析双值?

Java如何从收到的UDP字节解析双值?,java,byte,Java,Byte,???Double x=新的Doulbe.parseBytes(receivedpacket)您可以使用 你可以用 使用java.nio.ByteBuffer 比如: Double x = ByteBuffer.wrap(receiveData).getDouble(); 使用java.nio.ByteBuffer 比如: Double x = ByteBuffer.wrap(receiveData).getDouble(); 尝试使用DoubleBuffer。我喜欢您的实现。我自己也在使用

???Double x=新的Doulbe.parseBytes(receivedpacket)

您可以使用

你可以用


使用
java.nio.ByteBuffer

比如:

Double x = ByteBuffer.wrap(receiveData).getDouble();

使用
java.nio.ByteBuffer

比如:

Double x = ByteBuffer.wrap(receiveData).getDouble();

尝试使用
DoubleBuffer
。我喜欢您的实现。我自己也在使用同样的东西:pTry和
双缓冲区
。我喜欢你的实现。我自己也用同样的东西:p
private static ByteBuffer buffer = ByteBuffer.allocate(8);    

public static byte[] encodeDouble(double x) {
    buffer.clear();
    buffer.putDouble(0, x);
    return buffer.array();
}

public static double decodeDouble(byte[] bytes) {
    buffer.clear();
    buffer.put(bytes);
    buffer.flip(); 
    return buffer.getDouble();
}    
ByteBuffer.wrap(receiveData.getData()).getDouble();
java.io.DataInputStream.readDouble()