package cn.test;
import java.io.UnsupportedEncodingException;
public
class
Demo15 {
public
static
void main(String[] args) throws UnsupportedEncodingException {
String str =
"你好ABC123"
;
byte[] b1 = str.getBytes();
for
(byte b : b1) {
System.out.
print
(Integer.toHexString(b & 0xff) +
" "
);
}
System.out.println(
""
);
byte[] b2 = str.getBytes(
"utf8"
);
for
(byte b : b2) {
System.out.
print
(Integer.toHexString(b & 0xff) +
" "
);
}
System.out.println(
""
);
byte[] b3 = str.getBytes(
"gbk"
);
for
(byte b : b3) {
System.out.
print
(Integer.toHexString(b & 0xff) +
" "
);
}
System.out.println(
""
);
byte[] b4 = str.getBytes(
"utf-16be"
);
for
(byte b : b4) {
System.out.
print
(Integer.toHexString(b & 0xff) +
" "
);
}
System.out.println(
""
);
String str1 =
new
String(b4);
System.out.println(str1);
String str2 =
new
String(b4,
"utf-16be"
);
System.out.println(str2);
}
}