轉自:http://blog.csdn.net/aaronuu/article/details/7007386
1,byte[] str.getBytes(String charsetName)
返回用指定的字符集charsetName解碼後的字符數組。
2,String(byte[] bytes, String charsetName)
構造一個新的String.將字符數組bytes按着指定的字符集charsetName指定的字符集進行編碼。
String newStr = new String(str.getBytes("GB2312"),"ISO-8859-1");
這句話的意思是把str用GB2312編碼方式取出,將取出的字符數組用ISO-8859-1再進行編碼,來構造String類型對象newStr
相當於:
String str = "您好";
byte[] tbyte = str.getBytes("GB2312");//str用GB2312編碼方式取出
String newStr = new String(tbyte,"ISO-8859-1");//將tbyte轉換爲ISO-8859-1編碼形式