每日一句: Knowledge is a treasure, but practice the key to it. 知识是一座宝库,实践是打开宝库的钥匙。

java读取properties 文件信息

 

src下config/tank.properties文件

initTankCount=10
ReinitTankCount=8
Etmspeed=15
Mtmspeed=15
MTankCount=5
Level=1
ETankSpeed=8
MTankSpeed=8

 

PropertyMg .java

import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
  public class PropertyMg {
    static Properties props = new Properties();
    
    static {
        try {
            props.load(PropertyMg.class.getClassLoader().getResourceAsStream("config/tank.properties"));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    
     
    public static String getProperty(String key) {
        return props.getProperty(key);
     }
     
    
    public static void main(String args[]){
         
            int Etsize=Integer.parseInt(PropertyMg.getProperty("initTankCount"));
            System.out.println(Etsize    );
            System.out.println(PropertyMg.props.size() );
              PropertyMg.props.setProperty("size", "10");

             Enumeration<Object> e= PropertyMg.props.elements();
             Enumeration<Object> key=  PropertyMg.props.keys();
             while(e.hasMoreElements()&&key.hasMoreElements()){
                    String parameterName = (String) key.nextElement();
                    String parameterValue = (String) e.nextElement();
                   System.out.println(parameterName+":"+parameterValue);
              
                   }
     
    }
}

 

 

 

 

测试结果输出:

10
8
Etmspeed:15
MTankCount:5
Mtmspeed:15
initTankCount:10
ETankSpeed:8
Level:1
ReinitTankCount:8
MTankSpeed:8

posted @ 2013-08-19 09:27  wuyongmao  阅读(281)  评论(0编辑  收藏  举报