springBoot加载resources下静态文件

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

springBoot加载resources下静态文件

 

 

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

//获取文件
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();

 

上一篇:正则表达式(一):常用元字符


下一篇:Flutter误删除android/ios目录怎么办?