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