我有一个用 C 编写的二进制文件,我想用 java 读取它。我用 C 写了这样的文件:
void Log(TCHAR *name,int age){
write_int(file, 2012);
write_int(file, 4);
write_int(file, 16);
write_int(file, 12);
write_int(file, 58);
write_int(file, 50);
fwrite(&name, sizeof(name), 1, file);
fwrite(&age, sizeof(age), 1, file);
fflush(processusFile);
}
在 Java 中,我使用BinaryFile
类http://www.heatonresearch.com/code/22/BinaryFile.java我这样做:
RandomAccessFile f = new RandomAccessFile("myfile.dat", "r");
BinaryFile binaryFile = new BinaryFile(f);
ArrayList<String> text = new ArrayList<>();
while (true) {
try {
Calendar calendar = new GregorianCalendar();
int year = (int) binaryFile.readDWord();
int month = (int) binaryFile.readDWord();
int date = (int) binaryFile.readDWord();
int hourOfDay = (int) binaryFile.readDWord();
int minute = (int) binaryFile.readDWord();
int second = (int) binaryFile.readDWord();
calendar.set(year, month, date, hourOfDay, minute, second);
System.out.println(binaryFile.readFixedString(64));
catch (Exception e) {
break;
}
}
这对 char* 不起作用,但对 int 起作用。我如何编写字符串?