Java--io Class Character Stream overview

Source: Internet
Author: User

the reason and thought of character stream appearing
? Because the byte stream operation Chinese is not particularly convenient, so Java provides a character stream. Character stream = byte stream + encoding table.

Coding Table Overview and common coding tables Encoding Table
? A table consisting of characters and their corresponding values Common Coding Tables
? Ascii/unicode Character set? Iso-8859-1 Latin-1? Gb2312/gbk/gb18030? BIG5? UTF-8
public class Testmain {/* * getBytes (String charsetname); encodes this String into a byte sequence using the specified character set and stores the result in a new byte array.    string (byte[] bytes, string charsetname); constructs a new String by decoding the specified byte array with the specified charset. */public static void Main (string[] args) {string string = ' Hello World ';byte[] bytes = String.getbytes ();//Codingfor (int i=0;i<bytes.length;i++) {System.out.print (bytes[i]);//Output byte code}//decodingstring jiemastrin = new string (bytes);//Constructs a new String by decoding the specified byte array using the platform's default character set. //This platform is the operating system, the default encoding GBKSystem.out.print (' \ n ' +jiemastrin); } } public static void Main (string[] args) throws Unsupportedencodingexception {string string = ' Hello World ' Mei Hao ";//Codingbyte[] bytes = string.getbytes ("Utf-8"); //parameter does not write is using the system default GBK, but I was changed to Utf-8;for (int i=0;i<bytes.length;i++) {System.out.print (bytes[i]);//Output byte code}//decodingString Jiemastrin = new string (bytes);//Constructs a new String by decoding the specified byte array using the platform's default character set. (I've changed the default to Utf-8 here.)string jiemastrin = new String (bytes, "Utf-8"); //This platform is the operating system, the default encoding GBKSystem.out.print (' \ n ' +jiemastrin); } }


//unicode Code: Java Virtual machine internal use String str = "Mei Hao"; The stored string constant area is stored in Unicode code.


character Stream overview (conversion stream)
outputstreamwriter character output stream
     ?           Public OutputStreamWriter (OutputStream out); //Create a outputstreamwriter using the default character encoding.      ?   Public outputstreamwriter (OutputStream out,string charsetname);        InputStreamReader character input stream
     ?              Public InputStreamReader (InputStream in); //Create a inputstreamreader that uses the default character set.      ?       Public InputStreamReader (InputStream in,string charsetname); //Create a user with the specified character set
  






Java--io Class Character Stream overview

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.