该类可以通过new关键字创建其实例对象,该类的父类是抽象类Reader。
简单实例:
package com.FileInfo;
import java.io.File;
import java.io.FileReader;
public class FileInAndOutChar {
/**
* @param args
*/
public static void main(String[] args) {
//定义指定磁盘文件的File对象
File file = new File("F:/", "test.txt");
try {
if (!file.exists()) {
System.out.println("对不起,不包含有指定的文件!!");
} else {
//根据File对象创建FileReader对象
FileReader fr = new FileReader(file);
//定义char数组
char[] data = new char[23];
int length = 0;
while ((length = fr.read(data)) > 0) { //循环读取文件中的数据
//根据读取文件的内容创建String对象
String str = new String(data,0,length) ;
System.out.println(str);
}
fr.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}