将其存储在一个.properties
文件中。
配置属性
tile.size=16
screenshot.dir=..\\somepath\\..
阅读它
// Make sure this happens only the first time you start your application
Properties properties = new Properties();
// You can use FileInputStream, ClassLoader.getResourceAsStream or a reader too
properties.load(...)
使用它
int tileSize = Integer.valueOf(properties.getProperty("tile.size"));
String screenshotDir = properties.getProperty("screenshot.dir");
为了简化事情,并尽量减少更改,您还可以执行以下操作:
public class Globals {
private static final Properties properties = new Properties();
static {
// do the loading here
}
public static final int TILE_SIZE =
Integer.valueOf(properties.getProperty("tile.size"));
public static final String SCREENSHOT_DIR =
properties.getProperty("screenshot.dir");
// etc
}