2019年4月16日星期二

java读取resources文件遇到的一个问题

spring中用applicationContext.getResources获取到Resource类实例之后,因为打包为jar之后resource文件在jar中,不在文件系统中,通过resource.getURI().getPath()为null,可以通过resource.getURL().getPath()获取到路径,比如:file:/Users/chenxiaoyu/project/target/project-1.0-SNAPSHOT.jar!/BOOT-INF/classes!/data/xx.txt

没有评论:

发表评论