一、如圖,想要加載解析 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();