getResourceAsStream returns null

前端 未结 16 2550
臣服心动
臣服心动 2020-11-22 04:00

I\'m loading a text file from within a package in a compiled JAR of my Java project. The relevant directory structure is as follows:

/src/initialization/Life         


        
16条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 04:43

    There seems to be issue with the ClassLoader that you are using. Use the contextClassLoader to load class. This is irrespective of whether it is in a static/non-static method

    Thread.currentThread().getContextClassLoader().getResourceAsStream......

提交回复
热议问题