目前正在编写一个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) {
}
}