通常方法:
InputStream is = XXX.class
.getResourceAsStream("../resources/system.properties");
由于打包时候,配置文件无法跟随一起打包jar,程序运行会报错。
解决方法:
String rootPath = System.getProperty("user.dir").replace("\\", "/");
FileInputStream in = new FileInputStream(rootPath
+ "/resources/system.properties");
读取运行的jar路径,然后再读取同级目录下的配置文件。
来源:oschina
链接:https://my.oschina.net/u/3172055/blog/1629503