package demo.io;
import java.io.UnsupportedEncodingException;
class 字符串的编码和解码 {
public static void main(String[] args) throws UnsupportedEncodingException {
String str = "你好";
byte[] buf = str.getBytes("GBK");
System.out.println("\"你好\"对应的GBK编码:");
for (byte b : buf) {
System.out.print(b + " ");
}
System.out.println();
System.out.println("解码GBK:" + new String(buf, "GBK"));
System.out.println("----------------------------------------------------------");
buf = str.getBytes();
System.out.println("\"你好\"对应的UTF-8编码:");
for (byte b : buf) {
System.out.print(b + " ");
}
System.out.println();
System.out.println("解码UTF-8:" + new String(buf));
}
}