在 Java 中,DataOutputStream.writeDouble()在发送之前将 double 转换为 long,先写入高字节(Big endian)。
但是,C#BinaryReader.ReadDouble()以 Little Endian 格式读取。
换句话说:字节顺序不同,更改其中之一应该可以解决您的问题。
将 Java 中的字节顺序从 Big Endian 更改为 Little Endian 的最简单方法是使用 ByteBuffer,您可以在其中指定 endian 类型:例如:
ByteBuffer buffer = ByteBuffer.allocate(yourvaluehere);
buffer.order(ByteOrder.LITTLE_ENDIAN);
// add stuff to the buffer
byte[] bytes = buffer.array();
Run Code Online (Sandbox Code Playgroud)
然后,使用DataOutputStream.write()