PropertiesLoader.java
1.3 KB
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
49
50
51
52
53
54
package com.sunyo.energy.location.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.util.Properties;
/**
* @author gerry.zhang
* @version 1.0
* @description roperties属性文件加载
* @date 2014-5-29
*/
public class PropertiesLoader {
private static final Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
private static final String UNIT_PRICE = "/unitprice.properties";
/**
* load properties文件
*
* @param propertyFile
* @return
*/
public static Properties loadProperty(String propertyFile) {
InputStream in = PropertiesLoader.class.getResourceAsStream(propertyFile);
Properties properties = new Properties();
try {
properties.load(in);
} catch (Exception e) {
logger.error("解析文件失败:文件名={}", propertyFile, e);
}
return properties;
}
public static String getUnitPrice(String key) {
Properties properties = PropertiesLoader.loadProperty(UNIT_PRICE);
return properties.getProperty(key);
}
public static String get(String key, String propertyFile) {
Properties properties = loadProperty(propertyFile);
return (String) properties.get(key);
}
}