Netbeans,从res文件夹获取文件属性

disbfnqx  于 2022-11-10  发布在  其他
关注(0)|答案(2)|浏览(182)

我试图从res文件夹中获取属性文件,但我得到这个错误:

Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name res/Interfaz, locale es_ES

这是项目树:

这是我的简单代码:

public class Main {

    public static void main(String args[]) {
    System.out.println("Working Directory = " + System.getProperty("user.dir"));
    ResourceBundle rb = ResourceBundle.getBundle("res/Interfaz", Locale.getDefault());
    //String name = rb.getString("name");
    //System.out.println(name);   // Si el idioma del sistema es español, imprime "Nombre".

    }

}

我正在使用Netbeans 12

f1tvaqid

f1tvaqid1#

我找到了解决方案。由于我的项目是一个Maven项目,遵循Maven约定,我必须在项目的src/main/目录下创建一个新的resources文件夹。下次我使用Maven构建项目时,这个src/main/resources路径将自动标记为资源目录。
从代码中,我可以访问它:

ResourceBundle.getBundle("Interfaz", Locale.getDefault());
ohtdti5x

ohtdti5x2#

我的Maven\源文件\主文件

  • 资源
  • java

代码:ResourceBundle rb = ResourceBundle.getBundle("hcenterMod");

相关问题