[英]How to only get the first 8 bytes from a file from a DataInputStream java
当前正在编写一个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) {
}
}
对我来说很完美,也可能对其他人有帮助!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.