byte[] bytes = "中国人".getBytes("UTF-8");
for (byte b : bytes) {
int temp = 0;
if((int)b<0){
temp =  (256 + b);
}else{
temp = b;
}
String c = Integer.toHexString(temp).toUpperCase();//转十六进制
System.out.println(c);
}

解决方案 »

  1.   

    public static void main(String[] args) 
    {
    String str = "";
    Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]+");
    Matcher matcher = pattern.matcher(str);
    while(matcher.find()){
    String mStr = matcher.group();
    try{
    str = str.replaceFirst(mStr,URLEncoder.encode(mStr,"UTF-8"));
    } catch(Exception e){

    }
    }
    System.out.println(str);
    }