spring boot读取resource下的文件

        //Spring Resource API
        //m1
        //Resource resource = new ClassPathResource("classpath:xx.properties");

        //m2
        //@Autowired
        //ResourceLoader resourceLoader;
        //Resource resource = resourceLoader.getResource("classpath:resource.properties");

        //多个文件
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        try {
            Resource[] resources = resourcePatternResolver.getResources("classpath:config/xx*.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }


        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("excleTemplate/test.xlsx");
//this.getClass().getResourceAsStream("/") = this.getClass().getClassLoader().getResourceAsStream("") InputStream inputStream
= this.getClass().getResourceAsStream("/excleTemplate/test.xlsx"); InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("excleTemplate/test/xlsx");

 

posted @ 2020-09-07 14:59  一只爱喝果粒橙的程序员  阅读(511)  评论(0编辑  收藏  举报