public static Properties defaultProps = new Properties();
static {
try {
FileInputStream in = new FileInputStream("config.properties");
defaultProps.load(in);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getProperty(String database) {
return defaultProps.getProperty(database);
}
public static void main(String[] args) {
System.out.println(...key database?);
// this is the part where I try to test if I can print the property 'database'
// I also try to make it available to other classes, tried using public statics,
}
这是我从属性文件config.properties
中检索属性的代码。但是,我希望能够打印属性N(此处:database
)并能够在其他类中使用属性N.
感谢您的帮助。
答案 0 :(得分:0)
所以请致电
System.out.println(getProperty("database"));