用Java读取VB 5.0二进制文件
我有一个用 Visual Basic 5.0 编写的程序创建的二进制文件。该文件仅包含一堆来自 Visual Basic 世界的 Long
值。我知道 Visual Basic 5.0 中的 Long
大小为 4 个字节,但我不知道字节顺序。
我尝试使用各种“读取”方法通过 DataInputStream 解析文件,但我似乎得到“错误”(即负)值。
我怎样才能阅读并使用 Java 正确解释它? Visual Basic 5.0 中 Long 的字节顺序是什么?
下面是我正在尝试使用的某种代码;我正在尝试读取 2 个 Long 并将其打印在屏幕上,然后再读取 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 );
}
I have a binary file that is created from a program made in Visual Basic 5.0. The file just contains a bunch of Long
values from the Visual Basic world. I've understood that Long
in Visual Basic 5.0 is 4 bytes in size, but I do not know the byte order.
I tried parsing the file with DataInputStream using various "read"-methods, but I seem to get "wrong" (i.e. negative) values.
How can I read this and interpret it correctly with Java? What is the byte order for a Long in Visual Basic 5.0?
Below is some kind of code I'm trying to work with; I'm trying to read 2 Long
s and print the out on the screen, and then read 2 more etc.
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 );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 VB 在 x86 CPU 上运行,因此它的数据类型是小端字节序。另请注意,VB 中的
Long
与 Java 中的int
大小相同。我会尝试这样的事情:
Since VB runs on x86 CPUs, its data types are little-endian. Also, note that a
Long
in VB is the same size as anint
in Java.I would try something like this: