我有一个十六进制字符串(sA)从UTF8字符串转换。 当我将十六进制字符串sA转换为UTF8字符串时,我无法使用构建模式(运行文件.jar)在表单UI中显示它,但是当我以运行模式或调试模式运行时,UTF8字符串可以在窗体UI中显示。 我使用netbeans IDE 7.3.1。 我的代码如下:在java中显示UTF8字符串与构建模式时出现错误
public String hexToString(String txtInHex) {
byte[] txtInByte = new byte[txtInHex.length()/2];
int j = 0;
for (int i = 0; i < txtInHex.length(); i += 2) {
txtInByte[j++] = Byte.parseByte(txtInHex.substring(i, i + 2), 16);
}
return new String(txtInByte);
}
private String asHex(byte[] buf) {
char[] chars = new char[2 * buf.length];
for (int i = 0; i < buf.length; ++i) {
chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
}
return new String(chars);
}