获取 properties的值

package cn.necsthz.lvshitong.util;

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

public class MobliePropertiesUtil {

    private static String fileName = "/moblie.properties";

    private static Properties p = new Properties();

    static {
        InputStream in = null;
        try {
            in = MobliePropertiesUtil.class.getResourceAsStream(fileName);// 类加载器
            p.load(in);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static String get(String key) {
        String value = null;
        if (p.containsKey(key)) {
            value = p.getProperty(key);
        }
        return value;
    }
}

你可能感兴趣的:(获取 properties的值)