java简单读取properts 内容

public class PropertiesUtils
{
    /**
     * 日志记录类
     */
    private static final Log logger = LogFactory.getLog(PropertiesUtils.class);


    private static Properties config = null;
    static
    {
        InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream("mm_config.properties");
        config = new Properties();
        try
        {
            config.load(in);
            in.close();
        }
        catch (IOException e)
        {
            logger.error(e);
            System.out.println("");
        }
    }


    /**
     * 读取properties的全部信息
     * 
     * @see [类、类#方法、类#成员]
     */
    public static void readAllProperties()
    {
        try
        {
            Enumeration en = config.propertyNames();
            while (en.hasMoreElements())
            {
                String key = (String) en.nextElement();
                String Property = config.getProperty(key);
                System.out.println(key + Property);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            logger.error("ConfigInfoError" + e.toString());
        }
    }


    /**
     * 根据key读取value
     * 
     * @param key
     * @return
     * @see [类、类#方法、类#成员]
     */
    public static String readValue(String key)
    {
        // Properties props = new Properties();
        try
        {
            String value = config.getProperty(key);
            return value;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            logger.error("ConfigInfoError" + e.toString());
            return null;
        }
    }}


你可能感兴趣的:(java,exception,properties,String,null,Class)