读取properties文件
public static Properties getAllArgs() {
Properties properties = new Properties();
InputStream in = null;
String out = "";
try {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream("args.properties");
properties.load(in);
} catch (IOException e) {
Logger.getLogger(RpUtil.class).error("error", e);
throw new RuntimeException(e);
} finally {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return properties;
}
public static String getArgs(String key) {
Properties properties = new Properties();
InputStream in = null;
String out = "";
try {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream("args.properties");
properties.load(in);
out = properties.getProperty(key);
} catch (IOException e) {
// TODO Auto-generated catch block
Logger.getLogger(RpUtil.class).error("error", e);
} finally {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return out;
}
public static String getArgsSsdb(String key) {
Jedis ssdb = null;
try {
ssdb = new Jedis(RpUtil.getArgs(Contants.SSDB_IP), Integer.valueOf(RpUtil.getArgs(Contants.SSDB_PORT)).intValue());
if (ssdb.hexists(Contants.ZHUGE_IO_CONFIG, key)) {
return ssdb.hget(Contants.ZHUGE_IO_CONFIG, key);
} else {
return RpUtil.getArgs(key);
}
} catch (Exception e) {
// TODO: handle exception
Logger.getLogger(RpUtil.class).error("error", e);
} finally {
if (ssdb != null) {
ssdb.close();
}
}
return RpUtil.getArgs(key);
}