JAVA读取本地配置文件实例

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

public class FileProperties extends Properties{
    public FileProperties(){}
    public FileProperties(String s)
    {
        try
        {
            InputStream inputStream = getClass().getResourceAsStream(s);
            load(inputStream);
            inputStream.close();
        }catch (Exception e)
        {
            System.err.println("Exception in FileProperties(String): "
                    + e.toString()
                    + " for filename="
                    + s);
        }
    }
    public FileProperties(Properties properties) {
        super(properties);
    }
    public static String getMyProperty(String name){
        FileProperties fp = new FileProperties("/cms.properties");
        if ( fp != null ) {
            return fp.getProperty(name);
        } else {
            return null;
        }
    }
}

 属性配置文件cms.properties格式为:

#Socket_TIM_Z = 0 47 17 * * ?
Socket_TIM_J = 0 0 4 * * ?
Socket_TIM_ZZH = 2 * * ? * *

 

posted @ 2016-10-11 09:33  天清云澈  阅读(2289)  评论(0编辑  收藏  举报