论坛首页 Java企业应用论坛

java中16进制转换为字符串

浏览 4139 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (10) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-06-06  

// 转化十六进制编码为字符串===这个有用
 public static String toStringHexTest(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;
 }

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics