日期:2014-05-19  浏览次数:20705 次

浏览器用的编码
浏览器吧汉字转成字符
 比如说 下 变成 %E4%B8%8B
  。变成 %E3%80%82
java怎么把 %E4%B8%8B 变成 下
  %E3%80%82 变成 。

------解决方案--------------------
URLDecoder.decode()
URLEncoder.encode()
------解决方案--------------------
把%去掉

Java code
public static void main(String[] args) throws Exception {
        String str = "E4B88B";
        //String str = "E38082";
        int len = str.length()/2;
        byte[]data = new byte[len];
        
        for(int i = 0;i < len;i++){
            String temp = str.substring(2*i,2*(i+1));
            data[i]=(byte)Integer.parseInt(temp,16);
        }

        String newstr = new String(data); 
        System.out.println(newstr);
    }