在Eclipse项目中放置.properties文件的位置? [英] where to put .properties files in an Eclipse project?
问题描述
我有一个非常简单的属性文件测试我正在努力工作:(以下是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 =这是
something.else =这是别的东西
我也保存为 TestProperties_en_US.properties
/ p>
当我从Eclipse运行TestProperties.java时,它找不到属性文件:
java.util.MissingResourceException:
找不到基本名称的bundle TestProperties,locale en_US
我做错了什么?
将它放在你的一个源路径的根级别,或完全限定调用 getBundle
中的资源名称,例如
ResourceBundle.getBundle(com.example.test.TestProperties);
请参阅文档 ResourceBundle.getBundle(String,Locale,ClassLoader)
了解更多信息。
I have a very simple properties file test I am trying to get working: (the following is 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);
}
}
}
and TestProperties.properties in the same directory:
something=this is something
something.else=this is something else
which I have also saved as TestProperties_en_US.properties
When I run TestProperties.java from Eclipse, it can't find the properties file:
java.util.MissingResourceException:
Can't find bundle for base name TestProperties, locale en_US
Am I doing something wrong?
Put it at the root level of one of your source paths, or fully qualify the resource name in the call to getBundle
, e.g.
ResourceBundle myResources =
ResourceBundle.getBundle("com.example.test.TestProperties");
See the docs for ResourceBundle.getBundle(String, Locale, ClassLoader)
for more information.
这篇关于在Eclipse项目中放置.properties文件的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!