我想获取我从 build.properties 添加的属性的值
dergilik.host=http://172.171.1.155/
使用下面的代码
private final static String PROPERTIES_FILE = "build.properties";
private final static String HOST = "dergilik.host";
private final Properties props = new Properties();
private String getHost() {
try {
InputStream inp = new FileInputStream(PROPERTIES_FILE);
props.load(inp);
return props.getProperty(HOST);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
e.printStackTrace();
return null;
}
}
但是应用程序在props.load(inp);
. 我也用 ClassLoader 类尝试过,发生了 NullPointerException。此外,我将 PROPERTIES_FILE 更改为“/ProjectName/build.properties”,但它不起作用。
那么如何让程序正确找到 build.properties 文件呢?
谢谢