private static String convertResourceName ( Class < ? > klass , String resource ) { if ( resource . startsWith ( "/" ) ) { // "absolute" resource, chop the slash return resource . substring ( 1 ) ; } else { String className = klass . getName ( ) ; int i = className . lastIndexOf ( ' ' ) ; if ( i < 0 ) { // no package return resource ; } else { // need to be relative to the package String packageName = className . substring ( 0 , i ) ; String packagePath = packageName . replace ( ' ' , ' ' ) ; return packagePath + "/" + resource ; } } }
use ClassLoader directly .