import java.util.Arrays;
public class EncodeDemo {
public static void main(String[] args) throws Exception {
String s = "你好";
byte[] b1 = s.getBytes("GBK");
System.out.println(Arrays.toString(b1));
String s1 = new String(b1, "ISO8859-1");
System.out.println("s1 = " + s1);
// 对s1进行ISO8859-1编码
byte[] b2 = s1.getBytes("ISO8859-1");
System.out.println(Arrays.toString(b2));
String s2 = new String(b2, "GBK");
System.out.println("s2 = " + s2);
}
}
clipboard.png
clipboard.png
Tomcat默认编码ISO8859-1
网友评论