1. 程式人生 > >Java將http日誌資訊中char陣列轉中文顯示

Java將http日誌資訊中char陣列轉中文顯示

public static void main(String[] args) {
        String s="[0xe7][0x99][0xbe][0xe8][0x81][0x94][0xe5][0x95][0x86][0xe5][0x93][0x81]";
        String[] s_arr = s.substring(1,s.length()-1).split("\\]\\[");
        char[] cs=new char[s_arr.length];
        int z=0;
        for(String str : s_arr){
            cs[z] = (char
)Integer.parseInt(str.replace("0x",""), 16); z++; } byte[] ds = new byte[cs.length] ; for(int i=0;i<cs.length;i++){ ds[i]=(byte)cs[i]; } try { String t = new String(ds,"UTF-8"); System.out.println(t); } catch
(Exception e) { e.printStackTrace(); } }