一、项目的部署如下,现在要获取SystemGlobals.properties中的值
二、代码如下:
package com.util; import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; public class PropertiesTest {
public String getValue(String key)
{
Properties p =null; try
{
if(p == null)
{
InputStream is = getClass().getResourceAsStream("/SystemGlobals.properties");
p = new Properties();
p.load(is);
}
return p.getProperty(key);
}
catch (IOException e)
{
System.out.println("加载dbLink配置文件失败! ");
}
return null; } public static void main(String[] args) {
PropertiesTest p = new PropertiesTest();
//取出配置文件的值:p.getValue("montnets.emp.databaseIp")
System.out.println(p.getValue("montnets.emp.databaseIp")); } }