从java中的二进制文件读取Double时得到错误的值
RandomAccessFile in = new RandomAccessFile("BOT.grd", "r");
in.seek(28);
double xll=in.readDouble();
上面是我用来读取 29 到 36 字节位置的双精度数据的代码。当前的值是 500,但我得到 2.088E-317
RandomAccessFile in = new RandomAccessFile("BOT.grd", "r");
in.seek(28);
double xll=in.readDouble();
The above is the code i am using to read double data which is present from 29 to 36 byte location.The value present is 500 but i am getting 2.088E-317
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这个文件存储在与 java 使用的不同的 Endianness 中。在转换为双精度之前,字节可能需要反转,您可以尝试以下代码来读取该值:
这是一个说明问题的示例:
输出:
It seems this file is stored in a different Endianness than the one java uses. The bytes probably need to be reversed before converting to double, you could try the following code to read the value:
Here is an example that illustrates the problem:
Output: