1. 程式人生 > >java十六進位制轉換為字串(解決中文亂碼問題)

java十六進位制轉換為字串(解決中文亂碼問題)

 
 // 轉化十六進位制編碼為字串
	    public static String toStringHex2(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;
	    }