获取配置文件中配置信息
String xxx = DataParamReader.getDataParam("xxx");
public class DataParamReader {
private static Logger log = Logger.getLogger(DataParamReader.class);
private static final String PROPERTIES = "xxx.properties";
private static Properties dataProps = null;
private DataParamReader(){}
private static synchronized void getInstance() {
dataProps = new Properties();
try {
InputStream inputStream = Thread.currentThread()
.getContextClassLoader().getResourceAsStream(
PROPERTIES);
dataProps.load(inputStream);
log.info("读取配置文件:" + PROPERTIES);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
log.error("未发现配置文件:" + e2.getMessage());
} catch (IOException e1) {
log.error("读取配置文件出错:" + e1.getMessage());
} catch (Exception e) {
log.error("读取配置文件出错:" + e.getMessage());
}
}
public static String getDataParam(String name){
if (dataProps == null){
getInstance();
}
return dataProps.getProperty(name);
}
}