1. 程式人生 > >Idea配置文件的讀取

Idea配置文件的讀取

code string delay .get .class span cep fault png

開發過程中遇到配置文件讀取問題,因此記錄以後運用的到。

配置文件位置:

技術分享

配置文件內容:

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