import java.io.UnsupportedEncodingException;
public class t {
/**
* @param args 可以通过Windows preferences general WorkSpace 设置
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "我";
byte[] bytes = null;
try {
bytes = str.getBytes("GBK"); //2
System.out.println(bytes.length);
bytes = str.getBytes("UTF-8");//3
System.out.println(bytes.length);
//str = "我" 报错 此编码方式不支持
//但是这个为什么输出1 呢 求解
bytes = str.getBytes("ISO8859_1");
System.out.println(bytes.length);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}