IO新手。。一个小问题,希望大虾们不吝赐教。。
结贴是美德 2012-01-02 01:37:34 我这有两个try块儿,都是试图读一个纯文本文件,然后再显示出来,文件里中英文全有。。文件时用UTF-8存的
第二个中文乱码。。。我貌似知道原因,但是呢,为何第一个全是乱码,难道DataInputStream的理解不到位?
先谢谢大家了~~
try {
DataInputStream in = new DataInputStream(
new FileInputStream(
"C:\\Users\\Dodolook\\Workspaces\\MyEclipse 10\\IO\\src\\iostream\\FormattedMemoryInput.java"));
while (true)
System.out.print(in.readChar());
} catch (EOFException e) {
System.err.println("End of stream");
}
try {
FileInputStream in = new FileInputStream(
"C:\\Users\\Dodolook\\Workspaces\\MyEclipse 10\\IO\\src\\iostream\\FormattedMemoryInput.java");
int i;
while ((i = in.read()) != -1)
System.out.print((char) i);
} catch (EOFException e) {
System.err.println("End of stream");
}