SpringBoot读取resource中的文件

//使用File获取resources里面资源文件的相对路径 若文件名称为中文可能会报文件不存在
File file = new File(this.getClass().getResource("/province-city.josn").getPath());



//使用inputStream
InputStream inputStream = this.getClass().getResourceAsStream("/province-city.json");

 

posted @ 2020-08-19 15:20  y-xs  阅读(2933)  评论(0编辑  收藏  举报