java 16进制转String

来源:互联网 发布:sum在c语言中什么意思 编辑:程序博客网 时间:2024/05/22 02:02


 public static String toStringHex(String s) {
  byte[] baKeyword = new byte[s.length() / 2];
  for (int i = 0; i < baKeyword.length; i++) {
   try {
    baKeyword[i] = (byte) (0xff & Integer.parseInt(
      s.substring(i * 2, i * 2 + 2), 16));
   } catch (Exception e) {
    e.printStackTrace();
   }
  }

  try {
   s = new String(baKeyword, "utf-8");// UTF-16le:Not
  } catch (Exception e1) {
   e1.printStackTrace();
  }
  return s;
 }

原创粉丝点击