package file.Buffered;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class BufferedReader_ {
public static void main(String[] args) throws IOException {
String path = "d:\\news.txt";
//创建BufferedReader
BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
//读取
String line;//按行读取,效率高
/*
* bufferedReader.readLine()按行读取文件
* 当返回null时,表示文件读取完毕
*/
while((line = bufferedReader.readLine())!=null){
System.out.println(line);
}
//关闭流,只需要关闭BufferedReader,因为底层会自动关闭节点流
bufferedReader.close();
}
}
BufferedReader
最新推荐文章于 2024-09-01 15:30:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)