首页 > 其他 > 详细

Idea配置文件的读取

时间:2017-06-05 21:27:08      阅读:365      评论:0      收藏:0      [点我收藏+]

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

配置文件位置:

技术分享

配置文件内容:

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配置文件的读取

原文:http://www.cnblogs.com/huangyichun/p/6947092.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!