将以下函数:【 public static String readBinaryFileFile file try FileInputStream fis = new FileInputStreamfile byte fileData = new byteint filelength; fisreadfileData;
修改后的函数如下:
public static String readBinaryFile(File file) {
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) {
long length = randomAccessFile.length();
ByteBuffer buffer = ByteBuffer.allocate((int) length);
randomAccessFile.getChannel().read(buffer);
buffer.flip();
StringBuilder stringBuilder = new StringBuilder();
while (buffer.hasRemaining()) {
stringBuilder.append(buffer.get()).append(", ");
}
String result = stringBuilder.toString();
result = "[" + result.substring(0, result.length() - 2) + "]";//del /t/n
byte[] bt = result.getBytes();
String s = encodeHexString(bt);
s = "[" + s.substring(0, s.length() - 2) + "]";
System.out.println(s);
return s;
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
其中,findSignatureBlock方法没有提供,你需要自行实现。另外,encodeHexString方法也需要自行实现,可以使用javax.xml.bind.DatatypeConverter.printHexBinary方法替代
原文地址: http://www.cveoy.top/t/topic/isnU 著作权归作者所有。请勿转载和采集!