付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
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
package com.wgcloud.util;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;
 
/**
 * @version v3.3
 * @ClassName:PropertyUtil.java
 * @author: http://www.wgstart.com
 * @date: 2021年1月16日
 * @Description: PropertyUtil.java
 * @Copyright: 2019-2021 wgcloud. All rights reserved.
 */
public class PropertyUtil {
 
    public static Set<String> getKeys(String fileName) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream in = classLoader.getResourceAsStream(fileName);
        Properties p = new Properties();
        Set<String> keySet = null;
        try {
            p.load(in);
            keySet = p.stringPropertyNames();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return keySet;
    }
 
 
    public static String get(String fileName, String propertyName) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream in = classLoader.getResourceAsStream(fileName);
        Properties p = new Properties();
        String msg = "";
        try {
            p.load(in);
            msg = (String) p.get(propertyName);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return msg;
    }
 
 
}