Why does getResource return null

后端 未结 5 1739
感情败类
感情败类 2021-01-05 23:22

I\'m trying to access a file in my project. But getResource method returns null.

This is how my project looks like:

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 00:06

    There are lot of ways to add a resource to the jar file, you can put it in src, add as a resource if you use maven, ant etc... If you able to bundle whole directory then you should be able to use your original piece of code. With the current structure you can use following piece of code.

    Thread.currentThread().getContextClassLoader().getResource("/xxx.png"). 
    

提交回复
热议问题