String utf;
...
String gbk=new String(utf.getBytes("utf-8"),"gb2312");

解决方案 »

  1.   

    简单考虑,没有做任何检查,仅供参考
      public static void main(String[] args) {
        String str = "E4BABA";    
        
        String s = "";
        try {
          s = new String(getBytes(str),"utf-8");     
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
        System.out.println(s);
      }
      
      public static byte[] getBytes(String str){
        String temp = "";
        byte[] bytes = new byte[str.length()/2];
        
        for (int i = 0; i < str.length() / 2; i++) {
          temp = str.substring(i * 2, i * 2 + 2);
          bytes[i] = (byte)Integer.parseInt(temp, 16);
        }
        
        return bytes;
      }