public class test1{
public static void main(String [] args)throws UnsupportedEncodingException {
System.out.println("妖术".getBytes("ISO8859-1").length);
System.out.println("妖术".getBytes("GBK").length);
System.out.println("妖术".getBytes("GB2312").length);
System.out.println("妖术".getBytes("utf-8").length);
}
}
结果:
2
4
4
6
[color=red]
"ISO8859-1"占一个字符
GBK、GBK312占两个字符
utf-8占3个字符
[/color]