01.public class test {
02. public static void main(String[] args) {
03. String test = "小猫";
04. byte []bytes = test.getBytes();
05. int i = bytes.length;//i为字节长度
06. int j = test.length();//j为字符长度
07. System.out.println(i+" "+j);
08. }
09.}
10.//output:6 2
其实打印出来的i跟你的文件编码格式有关。UTF-8下,一个中文字是3个字节。