Get a resource using getResource()

前端 未结 4 825
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 12:37

I need to get a resource image file in a java project. What I\'m doing is:

URL url = TestGameTable.class.getClass().
          getClassLoader().getResource(\         


        
4条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 13:00

    TestGameTable.class.getResource("/unibo/lsb/res/dice.jpg");
    
    • leading slash to denote the root of the classpath
    • slashes instead of dots in the path
    • you can call getResource() directly on the class.

提交回复
热议问题