.properties读取

来源:互联网 发布:网络女主播电影的歌曲 编辑:程序博客网 时间:2024/06/02 00:42

 

String DBhost="";

int selectCount;

        Properties prop = new Properties();
        InputStream in;
        in = getClass().getResourceAsStream("a.properties");//平级,classes下
        prop.load(in);
        Set keyValue = prop.keySet();
        for (Iterator it = keyValue.iterator(); it.hasNext();) {
                String key = (String) it.next();
                if (key.equals("DBhost")) {
                   DBhost = (String) prop.get(key);
                } else if (key.equals("selectCount")){
                   selectCount =Integer.parseInt((String)prop.get(key));
                }
}
a. properties
DBhost=localhost
selectCount=2000

 

原创粉丝点击