Get a resource using getResource() Get a resource using getResource() java java

Get a resource using getResource()


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.


Instead of explicitly writing the class name you could use

this.getClass().getResource("/unibo/lsb/res/dice.jpg");


if you are calling from static method, use :

TestGameTable.class.getClassLoader().getResource("dice.jpg");