.properties讀取

 

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章