3

我有一个用 Visual Basic 5.0 制作的程序创建的二进制文件。该文件只包含一堆Long来自 Visual Basic 世界的值。我知道Long在 Visual Basic 5.0 中的大小是 4 个字节,但我不知道字节顺序。

我尝试使用各种“读取”方法使用 DataInputStream 解析文件,但我似乎得到了“错误”(即负)值。

如何阅读并使用 Java 正确解释它?Visual Basic 5.0 中Long的字节顺序是什么?

下面是我正在尝试使用的某种代码;我正在尝试阅读 2Long秒并在屏幕上打印出来,然后再阅读 2 秒等。

    try {
        File dbFile = new File(dbFolder + fileINA);
        FileInputStream fINA = new FileInputStream(dbFile);
        dINA = new DataInputStream(fINA);
        long counter = 0;

        while (true) {
            Integer firstAddress = dINA.readInt();
            Integer lastAddress = dINA.readInt();

            System.out.println(counter++ + ": " + firstAddress + " " + lastAddress);
        }
    }
    catch(IOException e) {
        System.out.println ( "IO Exception =: " + e );
    }
4

1 回答 1

5

由于 VB 在 x86 CPU 上运行,它的数据类型是 little-endian。另外,请注意LongVB 中的 a 与 Java 中的 a 大小相同int

我会尝试这样的事情:

int vbLong = ins.readUnsignedByte() +
             (ins.readUnsignedByte() << 8) +
             (ins.readUnsignedByte() << 16) +
             (ins.readUnsignedByte() << 24);
于 2011-06-20T11:25:33.127 回答