根據String 類的構造方法裏設定字符集的內容如下:
public String(byte[] bytes,String charsetName) throws UnsrpportedEncodingException
bytes -- 指定的字節數組;
charsetName -- 指定的字符集。
具體用法如下:
String string = "中國";
byte bytes[] = string.getBytes();
String s = new String(bytes,"shift_jis");
System.out.println(s);
所輸出的s是指定了字符集"shift_jis"的字符串。