[Java iO] _ character encoding notes

Source: Internet
Author: User

[Java iO] _ character encoding notes

Objectives of this chapter:
Learn about several common codes
Understanding the causes of garbled characters

3. Details

Encoding: in the computer world, any text exists in a specified encoding method, the most common in Java program development is the following encoding: ISO8859-1, GBK/gb2312, Unicode, UTF

The iso8859-1 encoding is a single-byte encoding and can only represent 0 ~ The character range of 255, mainly used in English.
GBK/gb2312: International Chinese encoding. It is used to represent Chinese characters and is a dual-byte encoding.
UNICODE: This encoding method is used in Java. It is also the most standard encoding, represented in hexadecimal notation. But this encoding is not compatible with iso8859-1 encoding.
UTF: Since Unicode does not support iso8859-1 encoding, it is easy to take up more space, and it also requires two byte encoding for English letters, so Unicode is not easy to transmit and store, therefore, UTF Encoding is produced. UTF Encoding is compatible with iso8859-1 encoding and can also be used to indicate all language characters. However, UTF Encoding is an uncertain length encoding with the length of the first character ranging from 1 to 6 bytes, this encoding is generally used in Chinese Web pages, because it can save space.

Get the local code Display

Public class charsetdemo01 {public static void main (string ARGs []) {system. out. println ("default system encoding:" + system. getproperty ("file. encoding "); // get the current system code }}

You can use the string class to convert character encoding.

Import Java. io. outputstream; import Java. io. fileoutputstream; import Java. io. file; public class charsetdemo02 {public static void main (string ARGs []) throws exception {file F = new file ("D:" + file. separator + "test.txt"); // instantiate the file class outputstream out = new fileoutputstream (f); // instantiate the output stream byte B [] = "China, hello! ". Getbytes (" ISO8859-1 "); // transcoding operation out. Write (B); // save out. Close (); // close }};

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.