java工具类-读配置文件

///读配置文件


import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
public class PropertiesUtils
{

    private static Map<String, String> propertiesMap = new HashMap<String, String>();

    private PropertiesUtils()
    {
        init();
    }
    private static PropertiesUtils salf = null;

    private  void init()
    {
        InputStream inStream = null;
        try
        {
            String templatePath = "D:\\menu.properties";
            inStream = new FileInputStream (templatePath);
            Properties properties = new Properties();
            properties.load (inStream);
            Set<Entry<Object, Object>> proEntrySet = properties.entrySet();
            for (Entry<Object, Object> entry : proEntrySet)
            {
                propertiesMap.put (entry.getKey() + "", entry.getValue() + "");
            }
        }
        catch (Exception e)
        {
        } finally
        {
        }
    }
    public static String getValue (String key, boolean reLoadFlag)
    {
        if (null == salf)
        {
            salf = new  PropertiesUtils();
        }
        if (reLoadFlag)
        {
            salf.init();
        }
        return salf.propertiesMap.get (key);
    }

    public static String getValue (String key)
    {
        return getValue (  key, false) ;
    }
}

java工具类-读配置文件,布布扣,bubuko.com

java工具类-读配置文件

上一篇:apache-cxf-2.6.3 spring集成配置


下一篇:Tomcat6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules