开发者

How can i read a configuration file using Java and get the parameters from there like in Zend Framework?

I have a ini file as following, which will be loaded when my Java application startup, also that file will be used in Zend Framework, as core configuration file for Desktop user and Web user. Like boot load file.

But how can i make/use such class in Java? So that i can call the parameters like object to get correct values? Please see also the Zend Framework example what i exactly mean to achieve.

main.java:

Configure configure = new Configure('/tmp/application.inig', 'production');
System.out.println(configure.production.display); // returns false
System.out.println(configure.test.direc开发者_StackOverflowtory); // 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

For example in Zend Framework i can do like this, and it works:

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


Use ini4j api it will do everting for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜