How to load a resource bundle from a file resource in Java?

前端 未结 14 877
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 08:19

I have a file called mybundle.txt in c:/temp -

c:/temp/mybundle.txt

How do I load this file into a java.util.Res

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 08:56

    From the JavaDocs for ResourceBundle.getBundle(String baseName):

    baseName - the base name of the resource bundle, a fully qualified class name

    What this means in plain English is that the resource bundle must be on the classpath and that baseName should be the package containing the bundle plus the bundle name, mybundle in your case.

    Leave off the extension and any locale that forms part of the bundle name, the JVM will sort that for you according to default locale - see the docs on java.util.ResourceBundle for more info.

提交回复
热议问题