GBK与UTF-8的中文是一个字符占几个字节

public class ContentEncode {
	 
	public static void main(String[] args) throws IOException {
		String msg ="性命生命使命a";
		//编码: 字节数组
		byte[] datas = msg.getBytes();  //默认使用工程的字符集
		System.out.println(datas.length);
		
		datas = msg.getBytes("GBK");
		System.out.println("GBK大小:"+datas.length);		
		
		datas = msg.getBytes("utf-8");
		System.out.println("utf-8大小:"+datas.length);
	}
 
}

运行结果:

编码:GBK 字节数:2
编码:UTF-8 字节数:3

猜你喜欢

转载自blog.csdn.net/springlan/article/details/105313136
今日推荐