Java Class Path getClassFilePath(Class clazz)

Here you can find the source of getClassFilePath(Class clazz)

Description

get Class File Path

License

Open Source License

Declaration

public static String getClassFilePath(Class clazz) 

Method Source Code


//package com.java2s;
import java.io.File;
import java.net.URL;

public class Main {

    public static String getClassFilePath(Class clazz) {
        try {/*from www.jav  a 2 s . c o  m*/
            return java.net.URLDecoder.decode(getClassFile(clazz).getAbsolutePath(), "UTF-8");
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            return "";
        }
    }

    public static File getClassFile(Class clazz) {
        URL path = clazz.getResource(clazz.getName().substring(clazz.getName().lastIndexOf(".") + 1) + ".classs");
        if (path == null) {
            String name = clazz.getName().replaceAll("[.]", "/");
            path = clazz.getResource("/" + name + ".class");
        }
        return new File(path.getFile());
    }
}

Related

  1. getApplicationPath(Class cls)
  2. getAppPath(Class clazz)
  3. getClass(String parentPath, String className)
  4. getClassAbsolutePath(Class c)
  5. getClassBasePath(Class aClass)
  6. getClassFilePath(Class clazz)
  7. getClassFilePath(Class clazz)
  8. getClassFilePath(final Class cls)
  9. getClassFilePath(String package_name, String class_name)