我正在尝试config.properties
从我的 JAR 本地目录中读取一个文件,该目录是从网站运行的。我尝试了一堆不同的代码,从 Streaming it 到获取类路径等。最后我现在尝试的是以下代码:
FileInputStream f = new FileInputStream("./config.properties");
if(f != null) {
prop.load(f);
db = prop.getProperty("database");
dbuser = prop.getProperty("dbuser");
dbpass = prop.getProperty("dbpass");
host = prop.getProperty("host");
iloc = prop.getProperty("iloc");
}
这在从 Netbeans 内部测试和运行时完美评估,但是第二次我将它放在网络上并运行它,它不再找到配置文件,即使它是同一个目录中的同一个文件。我试过有./
没有,还是一样的结果。