Java资源文件引用相关

同包引用资源文件 例如加载项目目录下的图片

this.getClass().getResourceAsStream("/img/logo.png");

Jar包内的类读取Jar包同级目录配置文件

#如果在静态代码块中加载 把this.getClass()换成 
类名.class
pop.load(new FileInputStream(newFile(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()+"/config.properties"));

posted @ 2021-02-24 16:01  ynsocool  阅读(74)  评论(0)    收藏  举报