中文占字节数

原来中文的占的字节数跟编码有关。java

String chinese = "a中午";
		byte[] b = chinese.getBytes("GBK");
		byte[] d = chinese.getBytes("gb2312");
		byte[] c = chinese.getBytes("utf8");
		System.out.println("GBK:"+b.length);              // 5
		System.out.println("gb2312:"+d.length);           // 5
		System.out.println("UTF8:"+c.length);            // 7

 GBK 和 gb2312编码下,一个中文占两个字节。 utf8编码的实际上是3个字节。编码

相关文章
相关标签/搜索