1. 程式人生 > >JAVA String中文亂碼

JAVA String中文亂碼

charset code bytes str1 new class tr1 ava col

            System.out.println(str);
            String str1 = new String(str.getBytes("ISO-8859-1"), "utf-8");
            System.out.println(str1);
            String str2 = new String(str.getBytes("gb2312"), "utf-8");
            System.out.println(str2);
            String str3 = new String(str.getBytes("gbk"), "utf-8");
            System.out.println(str3);

str.getBytes(charsetName);charsetName是原本字符的編碼

"utf-8"是將str轉換為utf-8編碼。

JAVA String中文亂碼