Junit + getResourceAsStream Returning Null

后端 未结 13 1399
情话喂你
情话喂你 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:37

    I always have problem with this method. Here are 2 links, which might be useful:

    • Describes diference between getClass().getResource(); and getClass().getClassLoader().getResource();
    • Simple utility which simplifies these 2 approaches

    I always experiment with adding "/" at the beginning or "./".

    From my experience the best method is using FileInputStream. There is only one thing to remember (while using FileInputStream with Eclipse), with default settings, your working directory is set to projects root. You can always check where is your current directory (and what relative paths you need)using this piece of code.

提交回复
热议问题