读取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);
    }
}

 

posted @ 2024-06-29 21:35  Bonnie_ξ  阅读(3)  评论(0编辑  收藏  举报