如题:
我在将某个字符串转成 utf-8 后,希望再将其转换为 Unicode 可是得不到希望的结果!public class Test { public static void main(String[] args) throws Exception {
String temp1 = "汉字";
System.out.println("temp1>>"+temp1);

String temp2 = new String(temp1.getBytes("utf-8"));//转utf-8
System.out.println("temp2>>"+temp2);

String temp3 = new String(temp2.getBytes());//想转 Unicode 
System.out.println("temp3>>"+temp3);  //不能输出 "汉字" 这两个字

}}

解决方案 »

  1.   

    URLEncoder.encode("汉字", "UTF-8");
    试试,再用这种方面转回Unicode 
      

  2.   

    这个问题已经说过无数次了
    temp1 是unicode  
    unicode 要转成utf8 需要先转成iso-8859-1 再转成utf8
      

  3.   

    你好像没有理解方法的用法。
    String temp2=newString(temp1.getBytes("utf-8"));
    是用utf-8解析,用默认gbk构造。所以,temp2是乱码。
    你应该这样String temp2=newString(temp1.getBytes("utf-8"),"utf-8");或String temp2=newString(temp1.getBytes("gbk"));
    temp2 = new String(temp2.getBytes("unicode"),"unicode");
      

  4.   


    package enCoding;
    public class Test {    public static void main(String[] args) throws Exception {
            String temp1 = "汉字";
            System.out.println("temp1>>"+temp1);
            
            String temp2 = new String(temp1.getBytes("utf-8"),"utf-8");//转utf-8
            System.out.println("temp2>>"+temp2);
            
            String temp3 = new String(temp2.getBytes("utf-8"),"utf-8");//想转 Unicode 
            System.out.println("temp3>>"+temp3);  //不能输出 "汉字" 这两个字
            
        }}请注意 new String()的参数,如果没有指定decode 方式,那么采用系统(或编译器)默认的处理,一旦不配套,肯定是显示乱码