对文字进行解码和编码
public class Test {
public static void main(String[] args) throws UnsupportedEncodingException {
//1.编码
String name = "我爱你中国abc";
byte[] bytes = name.getBytes();//以当前代码默认字符集进行编码(UTF-8)
System.out.println(Arrays.toString(bytes));
//byte[] gbks = name.getBytes("GBK");//指定字符集进行编码
//2.解码
String s = new String(bytes);
System.out.println(s);
String gbk = new String(bytes, "GBK");//以指定字符集进行解码
}
}