java.util.MissingResourceException:找不到基本名称'property_file name'的包,locale en_US [英] java.util.MissingResourceException: Can't find bundle for base name 'property_file name', locale en_US
问题描述
我正在尝试创建一个实用程序类 ReadPropertyUtil.java
,用于从属性文件中读取数据。虽然我的类位于util目录下,但我的 skyscrapper.properties
文件放在其他目录中。
I am trying to create a utility class ReadPropertyUtil.java
for reading data from property file. While my class is located under a util directory , my skyscrapper.properties
file is placed in some other directory.
但是,当我尝试使用 [ResourceBundle] [1]
访问属性时,我得到异常,无法加载该包。
But , when i try to access the properties using [ResourceBundle][1]
, i get exceptions, that bundle can't be loaded.
下面是关于我如何阅读属性的代码以及显示我的目录结构的图像。
Below is the code on how I am reading the properties and also an image which shows my directory structure.
ReadPropertiesUtil.java
/**
* Properties file name.
*/
private static final String FILENAME = "skyscrapper";
/**
* Resource bundle.
*/
private static ResourceBundle resourceBundle = ResourceBundle.getBundle(FILENAME);
/**
* Method to read the property value.
*
* @param key
* @return
*/
public static String getProperty(final String key) {
String str = null;
if (resourceBundle != null) {
str = resourceBundle.getString(key);
LOGGER.debug("Value found: " + str + " for key: " + key);
} else {
LOGGER.debug("Properties file was not loaded correctly!!");
}
return str;
}
目录结构
此行提供错误私有静态ResourceBundle resourceBundle = ResourceBundle.getBundle(FILENAME);
I我无法理解为什么这不起作用,解决方案是什么。 src
文件夹已完全添加到构建路径中。
I am unable to understand why isn't this working and what is the solution. The src
folder is already added in build path completely.
推荐答案
尝试使用资源的完全限定名称:
Try with the fully qualified name for the resource:
private static final String FILENAME = "resources/skyscrapper";
这篇关于java.util.MissingResourceException:找不到基本名称'property_file name'的包,locale en_US的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!