springBoot加载resources下静态文件


一、如图,想要加载解析 resources下的 test.txt

 

 

 二、方式一(获取流或者路径)

//获取文件
final File file = ResourceUtils.getFile("classpath:static/stop_words.txt");
//获取文件输入流
final FileInputStream inputStream = new FileInputStream(file);
//获取文件路径
final String path = ResourceUtils.getFile("classpath:static/stop_words.txt").getPath();

三、方式二

   ClassPathResource classPathResource = new ClassPathResource("static/test.txt");
   //获取流
  InputStream inputStream = classPathResource.getInputStream();
  //获取文件
  final File file = classPathResource.getFile();
  //获取路径
  final String path = classPathResource.getPath();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM