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
漫人生路上,该放下的要放下,往事如过眼烟云,浅笑则安...