Skip to content

Instantly share code, notes, and snippets.

@turbotree
Created September 9, 2014 02:43
Show Gist options
  • Save turbotree/e78cb71914a5e1a472a4 to your computer and use it in GitHub Desktop.
Save turbotree/e78cb71914a5e1a472a4 to your computer and use it in GitHub Desktop.
汉字所占字节与编码方式有关
public static void main(String []args) throws UnsupportedEncodingException {
// 运行结果:2
System.out.println("柳峰".getBytes("ISO8859-1").length);
// 运行结果:4
System.out.println("柳峰".getBytes("GB2312").length);
// 运行结果:4
System.out.println("柳峰".getBytes("GBK").length);
// 运行结果:6
System.out.println("柳峰".getBytes("UTF-8").length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment