http://blog.youkuaiyun.com/xxb2008
import java.nio.charset.Charset;
public class Helloworld{
//指定defaultCharset默认编码:-Dfile.encoding=GBK
//如果没有指定,系统会根据时区、操作系统的相关信息来获取。
//javac -encoding utf-8 Helloworld.java,如果文件为GBK编码,会报错。
//java -Dfile.encoding=utf-8 Helloworld
//javap -v Helloworld.class
public static void main(String[] args){
try{
User u = new User();
u.name="我";
System.out.println(u.name);
System.out.println(Charset .defaultCharset()); //UTF-8
System.out.println("默认长度-->" + u.name.getBytes().length);
System.out.println("utf8长度-3->" + u.name.getBytes("utf-8").length);
System.out.println("gbk长度-2->" + u.name.getBytes("GBK").length);
}catch(Exception e){}
}
}