读取resource下文件流或者路径
@Configuration @ConditionalOnExpression("${conditional.configuration.switch:true}") public class TaskScheduled { @Scheduled(cron = "15,30,45 * * * * ?") public void test1() throws FileNotFoundException { InputStream fileInputStream = this.getClass().getResourceAsStream("/json/save_db.json"); String path = this.getClass().getResource("/").getPath(); String s = path + "/json/save_db.json"; InputStream fileInputStream = new FileInputStream(s); System.out.println(fileInputStream); String read = IoUtil.read(fileInputStream, CharsetUtil.CHARSET_UTF_8); System.out.println(read); } }
故乡明