一、Java–IO流总体介绍与装饰者模式
这两篇博客介绍的很详细,强烈推荐。
二、文件读写代码练习
参考博客https://blog.csdn.net/jiangxinyu/article/details/7885518
1、FileReader流读
public static void main(String [] args){
FileReader fr;
{
try {
fr = new FileReader("src/ming.txt");
int ch = 0;
while((ch = fr.read())!=-1 )
{
System.out.print((char)ch);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2、BufferReader封装
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(new FileInputStream("src/ming.txt")));
String data = null;
while ((data = br.readLine()) != null){
System.out.println(data);
}
}