String sd = "Asdf";
String s = new String(sd.getBytes(),"gb2312");

解决方案 »

  1.   

    hexiaofeng(java爱好者),你说的是编码方式而不是解码方式吧???
      

  2.   

    sd为gb2312方式编码
    String sd = "Asdf"; 
    String s = new String(sd.getBytes(),"gb2312");
    s为解码后的字符串
      

  3.   

    String(byte[] bytes, String enc) 
              Construct a new String by converting the specified array of bytes using the specified character encoding.我试了,没用:
    一编码字符串为=?gb2312?B?peGjraXrhWfM5dSH8lnKy5iUlfhfUmV2MDAueGxz?=
    按上方法得到的字符串仍为=?gb2312?B?peGjraXrhWfM5dSH8lnKy5iUlfhfUmV2MDAueGxz?=
      

  4.   

    String f = "something";
    byte[] decoded = f.getBytes("gb2312");
    解码以后生成byte数组
    重新构造新的字符串:
    String newf = new String(decoded,"iso-8859-1");
      

  5.   

    {
          if(!s.startsWith("=?")) 
             return s;
          int i = 2;
          int j;
          if((j = s.indexOf(63, i)) == -1) 
             return s;
          String s1 = (s.substring(i, j));
          i = j + 1;
          if((j = s.indexOf(63, i)) == -1) 
             return s;
          String s2 = s.substring(i, j);
          i = j + 1;
          if((j = s.indexOf("?=", i)) == -1) 
             return s;
          String s3 = s.substring(i, j);
          try 
          {
             ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(s3.getBytes());
             Object obj;
             if(s2.equalsIgnoreCase("B")) 
                obj = new com.sun.mail.util.BASE64DecoderStream(bytearrayinputstream);
             else 
                if(s2.equalsIgnoreCase("Q")) 
                   obj = new com.sun.mail.util.QDecoderStream(bytearrayinputstream);
                else 
                   return s;
             int k = bytearrayinputstream.available();
             byte abyte0[] = new byte[k];
             k = ((InputStream)(obj)).read(abyte0, 0, k);
             return new String(abyte0, 0, k);
          }
          catch(Exception ex) 
          {
             return s;
          }
       }
      

  6.   

    漏了。
    public static String decodeWord(String s)
      

  7.   

    谢谢路人甲,你真是一个高人,pfpf