1. 程式人生 > >怎樣將GB2312編碼的字串轉換為ISO-8859-1編碼的字串?

怎樣將GB2312編碼的字串轉換為ISO-8859-1編碼的字串?

使用的函式:

public String(byte bytes[], String charsetName)
            throws UnsupportedEncodingException {
	this(bytes, 0, bytes.length, charsetName);
}

程式碼:

String s1 = "你好";
String s2 = new String(s1.getBytes("GB2312"), "ISO-8859-1");