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.io.UnsupportedEncodingException;

public class Main {
    public static String getClassFilePath(Class<?> clazz) {
        java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
        String filePath = null;/*from   ww w  . j  a  v  a 2 s  .  c om*/
        try {
            filePath = java.net.URLDecoder.decode(url.getPath(), "utf-8");
        } catch (UnsupportedEncodingException ignore) {
        }
        File file = new File(filePath);
        return file.getAbsolutePath();
    }
}

Related

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