package com.yihu.hos.web.framework.util.file;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;

/**
 *  获取配置文件内容滚工具类
 */
public class ConfigureUtil {

    /**
     * 获取.propertiest文件属性值
     * @param filePath  文件路径
     * @param key        属性名：key
     * @return value     属性值：value
     */
    public static String getProValue(String filePath, String key) {
        Resource resource = null;
        Properties props = null;
        String value = null;
        try {
            resource = new ClassPathResource(filePath);
            EncodedResource encRes = new EncodedResource(resource,"UTF-8");
            props = PropertiesLoaderUtils.loadProperties(encRes);
            value= (String) props.get(key);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return value;
    }
}
