Properties vs Resource Bundle

前端 未结 3 526
旧巷少年郎
旧巷少年郎 2020-12-23 19:34

I read about properties and resource bundle. But I was unable to get difference between these. When to use Properties file and when to use Resource bundle.

T

3条回答
  •  时光说笑
    2020-12-23 19:49

    Yes, you're thinking along the right lines.

    Resource bundles don't have to use property files - it's just one implementation (PropertyResourceBundle). A properties file is really just a string-to-string mapping - and that can be used for i18n, but doesn't have to be.

    ResourceBundle gives you a consistent way of requesting the appropriate object (usually a string) for a particular locale, with fallbacks etc. This is often, but not always, backed by a separate property file for each language.

    So yes: if you're dealing with i18n, you should use ResourceBundle; if you just need a string-to-string map persisted in a text file, it's fine to use Properties directly.

提交回复
热议问题