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

Netbeans, get file properties from res folder

我正在尝试从 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

好吧,我找到了解决方案。由于我的项目是Maven项目,按照Maven约定,我必须在项目的src/main/目录下新建一个resources文件夹。这个src/main/resources路径会在我下次使用Maven构建项目时自动标记为资源目录

从代码中我访问它是:

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

MyMaven\src\main

  • 资源
  • java

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