package util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 获取配置文件信息
*
* @author Carl
*
*/
public final class GetProperties {
private static Properties prop = null;
static{
prop = new Properties();
//设置properties文件路径,以src为根路径(config.properties 处于src根目录下)
InputStream in = GetProperties.class.getResourceAsStream("/config.properties");
try {
prop.load(in);
} catch (IOException e) {
System.out.println("读取配置文件失败---->>>>----(/src/config.properties)");//会失败!!!!
e.printStackTrace();
}
}
/**
* 根据传入的KEY获取配置文件中对应的值
* @param key
* @return
*/
public static String getPropertieValue(String key){
String value = "";
value = prop.getProperty(key).trim();
return value;
}
}
http://nannan408.iteye.com/blog/2022532