Everyone knows that Java's Char is a double byte character, while string provides the getbytes function. What kind of form does the bytes array obtained by this function exist? Is the Double Byte Character order in an array?
Do a test
String ts1 = "112 ";
Byte [] ts2 = NULL;
Ts2 = ts1.getbytes ();
This output is 112 ASCII 49 49 50
Note that this overload method adds an encoding parameter. Try another one.
String tests1 = "112 ";
Byte [] tests2 = NULL;
Try {
Ts2 = ts1.getbytes ("UTF-8 ");
} Catch (unsupportedencodingexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Output or 494950
String tests1 = "112 ";
Byte [] tests2 = NULL;
Try {
Ts2 = ts1.getbytes ("UTF-16LE ");
} Catch (unsupportedencodingexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Output to 490 490 500
Check out the SDK ,--! I wrote it too clearly ..
byte[] |
getBytes()
Use the default Character Set of the platformStringEncode the data as a byte sequence and store the results in a new byte array. |
byte[] |
getBytes(Charset charset)
Use the given charsetStringEncode the data to the byte sequence and store the results to the new byte array. |
The default charset of the system is GBK, while the Utf-8 uses variable Byte encoding and the Utf-16 uses two-byte fixed length encoding.