When using the following I get a NullPointerException
:
Class clazz = Foo.class;
String path = new File(clazz.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) + "";
However, it works when I use:
String path = new File(Foo.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) + "";
Is there any way around the NullPointerException
?