日期:2014-05-17 浏览次数:20877 次
public static void main(String[] args) {
String str = "中国";
System.out.println("系统默认编码:" + Charset.defaultCharset());
try {
//第一种情况
byte[] bytes1 = str.getBytes("GBK");
String newStr1 = new String(bytes1, "GBK");
System.out.println(newStr1);
//第二种情况
byte[] bytes2 = str.getBytes("UTF-8");
String newStr2 = new String(bytes2, "UTF-8");
System.out.println(newStr2);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}