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);
}
}
resultado de la operación:
Codificación: GBK Bytes: 2
Codificación: UTF-8 Bytes: 3