java.util.MissingResourceException:找不到基本名称“property_file name"的包,区域设置 en_US [英] java.util.MissingResourceException: Can't find bundle for base name 'property_file name', locale en_US

查看:26
本文介绍了java.util.MissingResourceException:找不到基本名称“property_file name"的包,区域设置 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;
}

目录结构

这一行给出了错误 private static ResourceBundle resourceBundle = ResourceBundle.getBundle(FILENAME);

我无法理解为什么这不起作用以及解决方案是什么.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"的包,区域设置 en_US的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆