zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    一个空类会生成哪些默认函数
    What is VMR(Video Mixing Render)From MSDN
    DirectX backface culling(背面剔除)
    D3DPOOL(资源池)
    两道概率题供大家周末把玩
    空间两点间的距离
    n != n, n == n
    C++默认参数
    D3DPT_TRIANGLELIST与D3DPT_TRIANGLESTRIP
    D3D中的设备丢失
  • 原文地址:https://www.cnblogs.com/J-wym/p/3267180.html
Copyright © 2011-2022 走看看