Java属性:.properties文件vs xml? [英] Java properties: .properties files vs xml?

查看:111
本文介绍了Java属性:.properties文件vs xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于属性我是新手,我读到XML是存储这些的首选方式。然而,我注意到,以

I'm a newbie when it comes to properties, and I read that XML is the preferred way to store these. I noticed however, that writing a regular .properties file in the style of

foo=bar
fu=baz

也有效。这意味着更少的打字(也许更容易阅读和更高效)。那么使用XML文件有什么好处?

also works. This would mean a lot less typing (and maybe easier to read and more efficient as well). So what are the benefits of using an XML file?

推荐答案

在XML中,您可以存储比在中更复杂(例如分层)的数据属性文件。所以这取决于你的用例。如果您只想存储少量直接属性,则属性文件更容易处理(尽管Java属性类也可以读取基于XML的属性)。

In XML you can store more complex (e.g. hierarchical) data than in a properties file. So it depends on your usecase. If you just want to store a small number of direct properties a properties file is easier to handle (though the Java properties class can read XML based properties, too).

它将配置界面保持为尽可能通用是有意义的,因此切换到另一个表示没有问题(例如,使用 Apache Commons配置)如果需要。

It would make sense to keep your configuration interface as generic as possible anyway, so you have no problem to switch to another representation ( e.g. by using Apache Commons Configuration ) if you need to.

这篇关于Java属性:.properties文件vs xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆