目前正在编写一个java swing程序。它从驱动器中获取所有文件并检查二进制签名。但我只想让文件的前2-8个字节来加速编程。尝试了大多数已经可用的解决方案,但没有一个与我已经编写的代码一起工作。
当前代码:
public void getBinary() {
try {
// get the file as a DataInputStream
DataInputStream input = new DataInputStream(new FileInputStream(file));
try {
// if files are avaliable countinue looping and get bytes / hex
while (input.available() > 0) {
// build a hex string from the bytes and change to uppercase
sb.append(Integer.toHexString(input.readByte()).toUpperCase());
// need to get the first couple of (8) bytes
}
} catch (IOException e) {
}
// print the hex out to command
// System.out.println(sb.toString());
} catch (FileNotFoundException e2) {
}
}
发布于 2016-11-29 21:43:37
对我来说很完美,也可以帮助其他人!
https://stackoverflow.com/questions/40721672
复制相似问题