我有一个非常简单的属性文件测试,我正试图开始工作:(以下是TestProperties.java)
package com.example.test; import java.util.ResourceBundle; public class TestProperties { public static void main(String[] args) { ResourceBundle myResources = ResourceBundle.getBundle("TestProperties"); for (String s : myResources.keySet()) { System.out.println(s); } } }
和TestProperties.properties在同一目录中:
something=this is something something.else=this is something else
我也将其另存为 TestProperties_en_US.properties
TestProperties_en_US.properties
当我从Eclipse运行TestProperties.java时,找不到属性文件:
java.util.MissingResourceException: Can't find bundle for base name TestProperties, locale en_US
难道我做错了什么?
将其放在您的源路径之一的根目录下,或在对的调用中完全限定资源名称getBundle,例如
getBundle
ResourceBundle myResources = ResourceBundle.getBundle("com.example.test.TestProperties");
有关ResourceBundle.getBundle(String, Locale, ClassLoader)更多信息,请参阅文档。
ResourceBundle.getBundle(String, Locale, ClassLoader)