import java.io.*;
public class Test4 {
public static void method(File file)
{
try (Reader reader=new FileReader(file)){
int i;
char[] chars=new char[1024];
while ((i=reader.read(chars,0,chars.length))!=-1)
{
System.out.println(new String(chars,0,i));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
method(new File("E:\\王若琳 - Lemon Tree (中文版).txt"));
}
}
方法同字节输入流,可以读取中文字符,本例中tet文档的保存格式为UTF-8,需和IDEA保持一致