Java Class Path getDirectoryPath(Class owner)

Here you can find the source of getDirectoryPath(Class owner)

Description

Get directory path according to Class.

License

Open Source License

Declaration

public static <T> String getDirectoryPath(Class<T> owner) 

Method Source Code


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

import java.io.File;

import java.net.URL;

public class Main {
    /**//from  w  ww. j ava  2  s . c o  m
     * Get directory path according to Class.
     */
    public static <T> String getDirectoryPath(Class<T> owner) {
        String packageName = owner.getPackage().getName().replace(".", String.valueOf(File.separator));
        URL resource = owner.getClassLoader().getResource(packageName);

        if (resource != null) {
            return resource.getPath();
        }

        return null;
    }
}

Related

  1. getClassFilePath(Class clazz)
  2. getClassFilePath(Class clazz)
  3. getClassFilePath(final Class cls)
  4. getClassFilePath(String package_name, String class_name)
  5. getClassNameByFile(String filePath, List className, boolean childPackage)
  6. getFile(Class base, String path)
  7. getFullPathOfClass(Class cls)
  8. getFullpathRessources(Class c, String ressource)
  9. getInputStream(Class cls, String path)