1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package mobvista.dmp.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @package: com.mobvista.dataplatform.utils
* @author: wangjf
* @date: 2019-08-26
* @time: 16:06
* @email: jinfeng.wang@mobvista.com
* @phone: 152-1062-7698
*/
public class PropertyUtil {
private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class);
private static Properties props;
synchronized static private void loadProps(String config) {
logger.info("start to load properties.......");
props = new Properties();
InputStream in = null;
try {
in = PropertyUtil.class.getClassLoader().
getResourceAsStream(config);
props.load(in);
} catch (IOException e) {
} finally {
try {
if (null != in) {
in.close();
}
} catch (IOException e) {
}
}
}
public static String getProperty(String config, String key) {
if (null == props) {
loadProps(config);
}
return props.getProperty(key);
}
}