ファイルに保存し.properties
ます。
config.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
}