java _io_ character set encoding _ _ _ decoding garbled

Computer knowledge byte characters do not know

Encoding : a byte character, encode
the decoded : from bytes to characters, decode

String s = "cool";
encoding:
byte [] = s.getBytes Data (); // encoding
System.out.println (data.length); // get the number of bytes
is encoded into other character sets:
Data = S. getBytes ( "utf8");

Decoding:
required: new String (bytes [] bytes , int offset, int length, String charsetName)
parameters were: byte array, where to begin (index), the length of the decoding, the character mode set

s = new String (data, 0, data.length, "utf8") // string decoded as the byte mode utf8

Distortion:
1, not the number of bytes (length decoding insufficient length)
2, the character set is not uniform

Guess you like

Origin blog.51cto.com/14437184/2422594