Package io.p7.encoding;
Import Java.io.BufferedWriter;
Import java.io.UnsupportedEncodingException; public class Encodedemo {public static void main (string[] args) throws unsupportedencodingexception {* * * string---&
gt; byte array: Encoding * byte array---> string: Decoding * Hello: gbk:-60,-29,-70,-61, * Hello: utf-8: -28,-67,-96,-27,-91,-67, * * If you're wrong and you don't know * * If you know what's wrong, there's a chance you'll be saved * (if you correspond to the text in another code table you can the text is coded and then the code is decoded in the correct code table. * But if you find the wrong code table and you don't have the text in that Code table,
The corresponding encoding of the word will be used in a special code to indicate that the special code can not be decoded into the correct text even if the correct code table is found) * * str= "Hello";
Byte[]buf=str.getbytes ("GBK");
String S1=new string (buf, "utf-8");
System.out.println ("s1=" +s1);
Byte[]buf2=s1.getbytes ("Utf-8");
String S2=new string (buf2, "GBK");
System.out.println ("s2=" +s2);
Encodedemo ();
The private static void Ncodedemo () throws unsupportedencodingexception {String str= "Hello";
Coded byte[]buf=str.getbytes ("Utf-8");
Printbytes (BUF);
Decodes string S1=new string (buf, "utf-8"); System.out.println ("S1= "+S1);
private static void Printbytes (byte[] buf) {for (byte b:buf) {System.out.print (b + ",");
}
}
}