If I use BufferReader to read a line, I can get a string of a line. The code is this :
FileInputStream fs = new FileInputStream("E:\\tmp\\aaa.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fs));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line.length() + " " +line.substring(0, 2);
}
The contents of aaa.txt is :
一二三四1234
so. the result of running the code is :
8 一二
From the result , I know the length of a chinese character in String is one, not two.
So If I use line.substring(0,2), I get two chinese character "一二". But I hope that, the result of line.substring(0,2) is "一".
I mean that, in my eye the length of "一二三四1234" is 12, not 8.I can use substring(0,2) to extract fixed length character.
Thanks in advance.