package day09IoAndProperties;
import java.io.FileReader;
import java.io.IOException;
public class Demo03Reader {
public static void main(String[] args) throws IOException {
//1.创建字符流对象
FileReader fr = new FileReader("D:\\JavaForward\\a.txt");
/*2.使用read方法读取单个字符
int len = 0;
while ((len = fr.read()) != -1) {
System.out.print((char) len);
}*/
//2.1使用字符数组读取多个字符
char[] chars = new char[1024];
int len = 0;
while ((len = fr.read(chars)) != -1) {
System.out.println(new String(chars, 0, len));
}
//3.关闭资源
fr.close();
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交