Query:different coding systems
Hello Everybody:
As we all know,FileReader and FileWriter are both character stream
classes.When I use FileReader to read a text file which combines letters
and Chinese Characters coding in ANSI's ascii.I know that each letter
holds one byte disk space to store while every Chinese Characters
occupies two.When that file has been read,it prints on the monitor
screen totally corresponds with it's content!
Now,here is my question:How does JVM identify one byte letter and two
byte Chinese Character?
Here is my program demo:
import java.io.*;
class FileReaderDemo{
public static void main(String[] args) throws Exception{
FileReader fr = new FileReader("text.txt");
int ch =0;
int words = 0;
while((ch =fr.read())!= -1){
System.out.print((char)ch);
words++;
}
fr.close();
System.out.println("\nThere are totally " + words + " characters in
this file!");
}
And the text.txt is:
This is a test file!
??????????????????
The outcome is:
This is a test file!
??????????????????
There are totally 31 characters in this file!
Thanks!
Dowson.