PropertyMgr.java
1 package config; 2 3 import java.io.IOException; 4 import java.util.Properties; 5 6 public class PropertyMgr { 7 8 private static final Properties props = new Properties(); 9 10 static { 11 try { 12 props.load(PropertyMgr.class.getClassLoader().getResourceAsStream("config/tank.properties")); 13 } catch (IOException e) { 14 e.printStackTrace(); 15 } 16 } 17 18 private PropertyMgr() {} 19 20 public static String getProperty(String key) { 21 return props.getProperty(key); 22 } 23 }
tank.properties
initTankCount=10
JavaSE配置文件java.util.Properties【单例模式Singleton】
原文:http://www.cnblogs.com/ErrStr/p/5173625.html