- public class TestEncode
- {
- public static void main(String[] args)
- {
- String str = "a工程师";
- try
- {
- System.out.println(str.getBytes("gbk").length);//结果7
- System.out.println(str.getBytes("utf-8").length);//结果10
- }
- catch (UnsupportedEncodingException e)
- {
- e.printStackTrace();
- }
- }
- }