Java Coded Table __java Learning

Source: Internet
Author: User
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 + ",");
 }
	}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.