范例:使用Reader读取
import java.io.File;
import java.io.FileReader;
import java.io.Reader;
public class Demo {
public static void main(String[] args) throws Exception {// 此处直接抛出错误
File file = new File("e:" + File.separator + "yummy.txt");
if (file.exists()) {
Reader in = new FileReader(file);
int temp = 0;
int foot = 0;
char[] data = new char[1024];
while ((temp = in.read()) != -1) {
data[foot++] = (char) temp;
}
System.out.println(new String(data, 0, foot));
in.close();
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/40480584ce2ff3cdcc65e98e6bab6def.png)
![](https://i-blog.csdnimg.cn/blog_migrate/88115e82f3c64f31bafa16ea772abb06.png)