2011-09-11 50 views
0

我有一個ini文件,它將在我的Java應用程序啓動時加載,也將在Zend Framework中用作Desktop用戶和Web用戶的核心配置文件。像啓動加載文件一樣。如何使用Java讀取配置文件並從Zend Framework中獲取參數?

但是我該如何在Java中創建/使用這樣的類?所以我可以調用像對象的參數來獲得正確的值?請參閱Zend框架示例,我的意思是實現。

main.java:

Configure configure = new Configure('/tmp/application.inig', 'production'); 
System.out.println(configure.production.display); // returns false 
System.out.println(configure.test.directory); // returns /tmp/another.ini 

/tmp/application.ini

[production] 
; this is a comment 
display = false 
; this is a comment 
security = true 

[test] 
complex = true 
directory = /tmp/another.ini 

例如Zend框架我可以這樣做,它的工作原理:

$config = new Zend_Config_Ini('/tmp/application.ini', 'production'); 
Zend_Debug::dump($config->display); // returns boolean type false 

回答

1

使用ini4j API它會爲你做翻轉。

相關問題