以GBK编码,再以utf-8解码的时候,解出来的数据就已经不是原来的字符串了,改变不回来了,但是反过来是可以的,,如:- public static void main(String[] args) throws UnsupportedEncodingException {
- String s = "你好";
- byte[] b1 = s.getBytes("UTF-8");
-
- System.out.println("b1=" + new String(b1,"UTF-8"));
- String s1 = new String(b1, "GBK");
- System.out.println("s1=" + s1);
- // 出现乱码。重新编译
- byte[] b2 = s1.getBytes("GBK");
-
- String s2 = new String(b2, "utf-8");
- System.out.println("s2=" + s2);
- }
复制代码 |