Java Class Path getPath(Class tClass)

Here you can find the source of getPath(Class tClass)

Description

get Path

License

Open Source License

Declaration

public static String getPath(Class tClass) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URL;

public class Main {
    public static String getPath(Class tClass) {
        String rtn = null;//from w w w. j  av  a  2 s  .  c  o  m
        URL url = getURL(tClass);
        if (url != null) {
            rtn = url.getPath();
            rtn = rtn.replace(tClass.getSimpleName() + ".class", "");
        }

        return rtn;
    }

    public static URL getURL(Class tClass) {
        URL rtn = null;
        if (tClass != null) {
            ClassLoader cl = tClass.getClassLoader();
            rtn = cl.getResource(tClass.getName().replace('.', '/') + ".class");
        }
        return rtn;
    }
}

Related

  1. getDirectoryPath(Class owner)
  2. getFile(Class base, String path)
  3. getFullPathOfClass(Class cls)
  4. getFullpathRessources(Class c, String ressource)
  5. getInputStream(Class cls, String path)
  6. getPath(final String aPath, final Class aClass)
  7. getPath(String name, Class relativeTo)
  8. getProgramRootPath(Class clazz)
  9. getRootAbsolutePathname(final Class clazz)