Encoding and decoding, encoding and decoding
Encoding:
Minimum byte Unit
String is a familiar unit.
Byte --- "character
String --- "byte
-------------------------------------
Decoding:
String ---> byte []; str. getBytes (charsetName );
Byte []-> String; new String (byte [], charsetName );
---------------------------------------
Garbled Problem
If the number is not changed, you can obtain and decode the number.
Bytep [] B = s1.getBytes ("iso8859-1 ");
String s = new String (B, "gbk ");
------------------------------------
China Unicom garbled
Coding and decoding in java
New String (strLine. getBytes ("iso8859-1"), "gb2312 ")
Actually, it is easy to understand here
First, convert the string to a byte array .. Converts to the encoding of the iso8859-1 ..
Create a new String with the byte [] array followed by the specific encoding ..
This method is generally used for transcoding .. Garbled characters often appear in JSP
Both Add the filter and use this new String (strLine. getBytes ("iso8859-1"), "gb2312") in the middle to convert the encoding.
What is encoding? What is decoding? Why encoding and decoding?
Encoding converts the content of the source object to a standard format.
Decoding corresponds to encoding. It uses the same standard as encoding to restore the encoding content to the original object content.
Codec was initially designed to encrypt information. It is difficult for people who do not know the encoding standard of the encrypted content to identify it. It has been around for thousands of years.
At present, there are many types of codec, and the main purpose is to exchange information.
In addition to encryption, common applications include character codec, HTML codec, URL codec, email codec, and multimedia codec. Encoding is to meet the transmission requirements, and decoding is to restore the information we can recognize.
For example, character encoding/decoding provides a ing between a series of numbers and characters that people want to see when entering text into a computer. Because there are different languages and texts in the world, we need to encode different texts for processing and transmission through computers.
Another example is multimedia codec. Because there are multiple formats of image sound, they each have their own codec standards.