PropertiesLoader.java 1.3 KB
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);
    }


}