- 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();
- }
- }
- }
本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1191872,如需转载请自行联系原作者