Package COM. CG. test; import Java. NIO. charset. charset; import Java. util. iterator; import Java. util. map; import Java. util. set; import Org. apache. commons. codec. binary. hex; public class hexstring {/*** @ Param ARGs */public static void main (string [] ARGs) throws exception {string S = "1A"; system. out. println ("original string:" + S); system. out. println (S. getbytes ("ASCII "). length); string sencoded = hex. encodehexstring (S. getbytes ("ASCII"); system. out. println ("ASCII:" + sencoded); sencoded = hex. encodehexstring (S. getbytes ("GBK"); system. out. println ("GBK:" + sencoded); system. out. println ("Default charset:" + charset. defaultcharset (). name (); sencoded = hex. encodehexstring (S. getbytes (); system. out. println ("Default:" + sencoded); // output: bytes 1e59bbd // BOM: byte order mark in byte sequence mark sencoded = hex. encodehexstring (S. getbytes ("Unicode"); system. out. println ("UNICODE:" + sencoded); // output: feff0031006156fdsencoded = hex. encodehexstring (S. getbytes ("UTF-16"); system. out. println ("UTF-16:" + sencoded); // output: feff0031006156fdsencoded = hex. encodehexstring (S. getbytes ("x-UTF-16LE-BOM"); system. out. println ("x-UTF-16LE-BOM:" + sencoded); // output: fffe31006100fd56sencoded = hex. encodehexstring (S. getbytes ("UTF-16BE"); system. out. println ("UTF-16BE:" + sencoded); // output: 0031006156 fdsencoded = hex. encodehexstring (S. getbytes ("UTF-16LE"); system. out. println ("UTF-16LE:" + sencoded); // output: 31006100fd56system. out. println ("returns the character set that can be used in the current JVM"); map M = charset. availablecharsets (); Set set = m. keyset (); iterator it = set. iterator (); While (it. hasnext () {system. out. println (it. next ());}}}