/*标签:编码,String,解码,b1,ISO8859,byte,s1 From: https://blog.51cto.com/u_10028442/5824124
* 编码:字符串变成字节数组
* 解码:字节数组变字符串
*
* String-->byte[];str.getBytes(charsetName);
*
* byte[]-->String;new String(byte[],charsetName)
*/
public class EncodeTest {
public static void main(String[] args) throws IOException {
String s="你好";
byte[] b1=s.getBytes("GBK");//编码
System.out.println(Arrays.toString(b1));
String s1=new String(b1,"ISO8859-1");//错误解码
System.out.println(s1);
//对s1进行ISO8859-1编码
byte[] b2=s1.getBytes("ISO8859-1");//编码
String s2=new String(b2,"gbk");
}
}