如果不是放在src文件夹里面,则:
p.load(new BufferedInputStream(new FileInputStream("tank.properties")));
如果是放在src文件夹,不在config文件夹里面,则:
p.load(Reflection.class.getResourceAsStream("../client/client.properties"));
如果是放在src文件夹,在config文件夹里面,则:
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