java 读取文本文件
1、新建springboot项目,如下

2、创建一个包含main方法的class
public class HellowWorldController {
public static void main(String[] args) {
String filePath = "D:\\test.txt";
FileReader fr = null;
BufferedReader bf = null;
try {
fr = new FileReader(filePath);
bf = new BufferedReader(fr);
String str = null;
// 按罩闲匠行读取字符串
while ((str = bf.readLine()) != null) {
System.out.println(str);
}
斤棍 }catch (Exception e){
//log error
}finally {
try {
if(bf!=null){bf.close();}
if(fr!=null){fr.close();}
} catch (IOException e) {
//log error
}
}
}
}

3、在D盘新建了一个test.txt文件,内容为“宙此hello world”

4、运行结果

阅读量:91
阅读量:31
阅读量:33
阅读量:79
阅读量:40