Java 9.0 | ClassLoader::getResourceAsStream: NullPointerException

前端 未结 1 1800
时光说笑
时光说笑 2021-02-08 12:41

This piece of code down below, where I take my file from folder which is inside the \"/resource\" folder, works fine for me in Java 8:

//e.g fileName =         


        
相关标签:
1条回答
  • 2021-02-08 13:26

    In the module_info.java file, you have to open the files, for example, the package name, in which you have the files is "resources" and, if that package is inside another called "resources_module" the code will be:

    exports resources_module;
    opens resources;
    opens resources.(the name of another folder inside the package);
    

    And now you can access to that folder.

    HOW TO ACCESS TO RESOURCES FROM ANOTHER CLASS

    1. Inside the package "resources_module" create a empty class
    2. From another class (including other modules), to get an InputStream you have to call the class you created before (the empty class) like this:

      (Your empty class).class.getResourceAsStream(path);

    0 讨论(0)
提交回复
热议问题