首页 > 代码库 > Idea配置文件的读取

Idea配置文件的读取

开发过程中遇到配置文件读取问题,因此记录以后运用的到。

配置文件位置:

技术分享

配置文件内容:

default_size = 100
grid_size = 20
delayTime = 200

配置文件读取方式:

public void initProperties() {
        Properties properties = new Properties();
        String path = LifeGame.class.getClassLoader().getResource("lifeGame.properties").getPath();
        File file = new File(path);
        try {
            FileInputStream inputStream = new FileInputStream(file);
            properties.load(inputStream);
            delay = Integer.parseInt(properties.getProperty("delayTime"));
            tableSize = Integer.parseInt(properties.getProperty("default_size"));
            gridSize = Integer.parseInt(properties.getProperty("grid_size"));
            currentMap = new int[tableSize][tableSize];
            neighbors = new int[tableSize][tableSize];
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

Idea配置文件的读取