-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropertyUtils.java
More file actions
60 lines (46 loc) · 1.35 KB
/
PropertyUtils.java
File metadata and controls
60 lines (46 loc) · 1.35 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
55
56
57
58
59
60
package com.util;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.util.Properties;
/**
* 获取工程外的properties文件。
* @author lenovo
*
*/
@Slf4j
public class PropertyUtils {
private static Properties props;
public static final String PATH_PROPERTIES="E:\\Test\\path.properties";
static{
loadProps();
}
synchronized static private void loadProps(){
log.info("开始加载"+PATH_PROPERTIES+"的properties文件内容.......");
props = new Properties();
InputStream in = null;
try {
in =new BufferedInputStream(new FileInputStream(PATH_PROPERTIES)) ;
props.load(in);
} catch (FileNotFoundException e) {
log.error("properties文件未找到");
} catch (IOException e) {
log.error("出现IOException");
} finally {
try {
if(null != in) {
in.close();
}
} catch (IOException e) {
log.error("properties文件流关闭出现异常");
}
}
log.info("加载properties文件内容完成...........");
}
public static String getProperty( String key){
String value=null;
if(null == props ) {
loadProps();
}
return props.getProperty(key);
}
}