Junit + getResourceAsStream Returning Null

后端 未结 13 1405
情话喂你
情话喂你 2020-12-15 03:32

Not sure how this is possible. I re-read up on getResourceAsStream and it\'s always returning null.

InputStream source = this.getClass().getResourceAsStream(         


        
13条回答
  •  甜味超标
    2020-12-15 03:52

    From Java API:

    http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getSystemResource(java.lang.String)

    Find a resource of the specified name from the search path used to load classes. This method locates the resource through the system class loader

    So the syntax will for instance be: ClassLoader.getSystemResource("test.xml").toString();

    Works like a charm!

提交回复
热议问题