// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;

public class GetPath {
    private static String getPath(Class cls) {
        String cn = cls.getName();
        String rn = cn.replace('.', '/') + ".class";
        String path = GetPath.class.getClassLoader().getResource(rn).getPath();
        int ix = path.indexOf("!");
        if(ix >= 0) {
            path = path.substring(0, ix);
        }
        return (new File(path)).getParent();
    }
    public static void main(String[] args) {
        System.out.println(GetPath.getPath(GetPath.class));
        System.out.println(GetPath.getPath(String.class));
    }
}
