package com.itheima.charstream1;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
public class CharStreamDemo2 {
public static void main(String[] args) throws IOException {
//method1();
byte[] bytes1={-23, -69, -111, -23, -87, -84, -25, -88, -117, -27, -70, -113, -27, -111, -104};
byte[] bytes2={-70, -38, -62, -19, -77, -52, -48, -14, -44, -79};
//UTF-8解码
String s1=new String(bytes1);
System.out.println(s1);
//gbk解码
String s2=new String(bytes2,"gbk");
System.out.println(s2);
}
private static void method1() throws UnsupportedEncodingException {
String s="黑马程序员";
//UTF-8汉字编码为字节,3个字节一个汉字
byte[] bytes1 = s.getBytes();
System.out.println(Arrays.toString(bytes1));
byte[] bytes2 = s.getBytes("UTF-8");
System.out.println(Arrays.toString(bytes2));
byte[] bytes3 = s.getBytes("GBK");
System.out.println(Arrays.toString(bytes3));
}
}
|