GjqDream

1、目标:想要读取该项目中的resources下的prop文件夹中的text.txt文件

2、实现方法:

// 读文件
String path = this.getClass().getClassLoader().getResource("./prop/text.txt").getPath();
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);

String str = null;
while((str = br.readLine()) != null) {
    System.out.println(str);
}

// 关闭流
br.close();
fr.close();

 

参考:

1)javaweb(实用)-IDEA下resources目录下txt文件读取写入引发的项目后台路径问题总结

分类:

技术点:

相关文章:

  • 2021-11-19
  • 2021-10-24
  • 2021-12-13
  • 2021-06-02
  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2022-01-04
  • 2022-12-23
  • 2021-08-09
  • 2022-01-18
相关资源
相似解决方案