xuekang
2024-05-11 bac0878349a1db23e7b420ea164e22fb9db73a99
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
package com.nuvole.util;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
 
/**
 * 读取配置文件
 *
 * @Author: lc
 * @Date: 2019/6/13 15:31
 */
@Slf4j
public class PropertyUtil {
 
    public static String getProp(String fileName, String k) {
        Properties props = new Properties();
        InputStream in = null;
        try {
            ResourceLoader resourceLoader = new DefaultResourceLoader();
            in = resourceLoader.getResource(fileName).getInputStream();
            props.load(in);
            return props.getProperty(k);
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        } finally {
            ResourceUtil.safeClose(in);
        }
    }
}