不好意思代码的二行写错了,应该为
byte[] b = strTemp.getBytes();

解决方案 »

  1.   

    char c='我';
    System.out.println(Integer.toHexString((int)c));
    注意是单引号,不要搞错了。
    你可以用String的charAt等方法获得char
      

  2.   

    public static String getUnicodeValue(String asString) {
        //String lsStrinUTF8 = new String(asString.getBytes(),"Cp1252");
        //char[] ac = lsStrinUTF8.toCharArray();
        char[] ac = asString.toCharArray();
        int iValue;
        String s = null;
        StringBuffer sb = new StringBuffer();    for (int ndx = 0; ndx < ac.length; ndx++) {
          iValue = ac[ndx];      if (iValue < 0x10) {
            s = "\\u000";
          }
          else if (iValue < 0x100) {
            s = "\\u00";
          }
          else if (iValue < 0x1000) {
            s = "\\u0";
          }
          else {
            s = "\\u";
          }
          sb.append(s + Integer.toHexString(iValue));
        }
        return sb.toString();
      }