package twenty_one;
import java.io.*;
import java.util.Arrays;
public class Seven {
public static void main(String[] args)throws IOException {
String s="你好";
byte[]b1=s.getBytes("GBK");//默认编码不写也行。
System.out.println(Arrays.toString(b1));
String ss=new String(b1,"ISO8850-1");
System.out.println("ss="+ss);
//对ss进行ISO8850-1编码
byte[]b2=ss.getBytes("ISO8850-1");
System.out.println(Arrays.toString(b2));
String sss=new String(b2,"gbk");
System.out.println("sss="+sss);
}
}
这段代码运行后出现:
[-60, -29, -70, -61]
Exception in thread "main" java.io.UnsupportedEncodingException: ISO8850-1
at java.lang.StringCoding.decode(StringCoding.java:170)
at java.lang.String.<init>(String.java:443)
at java.lang.String.<init>(String.java:515)
at twenty_one.Seven.main(Seven.java:9)
这种错误是怎么回事啊?
|
|