【发布时间】:2016-06-22 15:04:35
【问题描述】:
我正在尝试制作一个 Java 程序来编辑存储在 .bin 文件的偏移量中的一些文本(该文件是十六进制,但它是一个 .bin 文件)。这是我的班级尝试这样做:
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import java.io.*;
public class Class{
public static String getOffsetText(String offset, File bin){
String txt = null;
try{
byte[] off = Hex.decodeHex(offset.toCharArray());
txt = new String(off, "UTF-8");
}catch(DecodeException | UnsupportedEncodingException e){
e.printStackTrace();
}
return txt;
}
}
这是错误:
org.apache.commons.codec.DecoderException: Illegal hexadecimal character x at index 1
at org.apache.commons.codec.binary.Hex.toDigit(Hex.java:178)
at org.apache.commons.codec.binary.Hex.decodeHex(Hex.java:91)
第一个注意事项:我的带有 main 方法的类只是尝试在 GUI 中使用此方法。此外,Eclipse 没有显示我的代码有任何错误或警告。
第二个注意事项:我拥有的 .bin 文件可能已加密,但我不完全确定它们是否加密。
【问题讨论】: