test code
1
public class hello
{
2
public static void main(String a[]) throws java.io.IOException
{
3
String tmp = " 中文 " ;
4
printHex(tmp, " Unicode " );
5
printHex(tmp, " GB2312 " );
6
printHex(tmp, " ISO8859-1 " );
7
printHex(tmp, " UTF-8 " );
8
}
9 
10
private static void printHex(String str,String charset) throws java.io.IOException
{
11
byte [] buf = str.getBytes(charset);
12
for ( int i = 0 ; i < buf.length; i ++ )
{
13
System.out.print(Integer.toHexString(buf[i]));
14
System.out.print( " " );
15
}
16
System.out.println( " " );
17
}
18 
19
}