byte[] by = string.getBytes(Charset charset) 传人指定的编码。
使用给定的 charset 将此 String 编码到 byte 序列,并将结果存储到新的 byte 数组。
例如:结果 中文字都是用负数表示。- class CharSet {
- public static void main(String[] args) throws Exception{
- String str = "你好";
- byte[] by = str.getBytes("GBK");
- for (byte b : by){
- System.out.println(b);
- }
- }
- }
复制代码 结果:
希望能帮到你
|