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();
        }
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM