今天要调用api,然后要将返回的biz_content参数转成字符串形式存入数据库, 于是记录一下16进制转换为字符串的方法。
public static String hexStr2Str(String hexStr) { String str = "0123456789ABCDEF"; char[] hexs = hexStr.toCharArray(); byte[] bytes = new byte[hexStr.length() / 2]; int n; for (int i = 0; i < bytes.length; i++) { n = str.indexOf(hexs[2 * i]) * 16; n += str.indexOf(hexs[2 * i + 1]); bytes[i] = (byte) (n & 0xff); } return new String(bytes); }
16进制直接转换成为字符串(无需Unicode解码)
最新推荐文章于 2024-06-19 22:06:28 发布