getSystemResourceAsStream() returns null

前端 未结 3 1384
终归单人心
终归单人心 2020-12-06 02:38

Hiii... I want to get the content of properties file into InputStream class object using getSystemResourceAsStream(). I have built the sample code. It works well using

3条回答
  •  遥遥无期
    2020-12-06 03:33

    The SystemClassLoader loads resources from java.class.path witch maps to the system variable CLASSPATH. In your local application, you probably have the resource your trying to load configured in java.class.path variable. In the server, it's another story because most probably the server loads your resources from another class loader.

    Try using the ClassLoader that loaded class using the correct path:

    getClass().getResourceAsStream(fileName);
    

    This article might also be useful.

提交回复
热议问题