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