开发者

java properties files, using a key as another keys value, is this possible

I would like to know if there is any way to use a key as another key's value in .properties files.

For example is this possible, or is there any other way to achieve something similar to this?

key = another_key

app.name=Stack Over Flow  
app.title.welcome=Welcome to {app.name} 

so when i get the value of app.title.welcome it should be "Welcome to Stack 开发者_如何学PythonOver Flow"


The Apache Commons Configuration Project has an implementation capable of doing variable interpolation.

Read the section named Variable Interpolation

application.name = Killer App
application.version = 1.6.2
application.title = ${application.name} ${application.version}

You would need this third-party library in your class path, but on the other hand you will not have to worry about writing yet another implementation for this :)

You might like to read the Properties How To as well.


You might want to check out Apache Commons Configuration. It does what you're looking for and more.


With java.util.Properties - no. But if you write the proper resolver - it is. And writing that resolver won't be that hard. Just look for {..} in each value and whenever encountered look for that key.


You can just write app.title.welcome=Welcome to {0} and pass app.name as a parameter in Java code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜