我已经写了一个类,加载我的程序中使用的外部属性,它建模了这个链接:Load Properties File in Singleton Class。我已阅读(FileNotFoundException with properties file)和这里(Java Properties File not loading)如何加载外部属性文件,但我继续得到FileNotFoundException。我的属性文件是外部的,位于与我的可执行文件相同的目录中。Java - 加载外部属性文件 - FileNotFoundException
公共类ExternalProperties扩展属性{
private static ExternalProperties instance = null;
private Properties properties;
private static String location;
protected ExternalProperties() throws IOException {
properties = new Properties();
properties.load(getClass().getResourceAsStream("test.properties"));
}
public static ExternalProperties getInstance(){
if(instance == null){
try{
instance = new ExternalProperties();
} catch (IOException e) {
e.printStackTrace();
}
}
return instance;
}
public static void setLocation(String path){
location = path;
}
}
我传递的属性文件的位置,通过命令行如:
Java的罐子厨师 - 部署 - 测试-0.0.0009-SNAPSHOT-jar -with-dependencies.jar test.properties
对我在做什么有什么建议吗?