/**
* 使用IO 流读取本地文件
*/
public class FileReadWrite {
public static void main(String[] args) {
FileReader fr = null;
try {
//1. 创建读取文件
fr = new FileReader(new File("E:\\11.txt"));
//每次读取多少个字符
char[] chas = new char[1024];
int len;
while ((len = fr.read(chas)) != -1) {
// 方式一:
// for (int i = 0; i < len; i++) {
// System.out.print(chas[i]);
// }
//方式二:
String str = new String(chas,0, len);
System.out.println(str);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}