Java ClassPath findDirectoryFromClasspath(Class cls, String file)

Here you can find the source of findDirectoryFromClasspath(Class cls, String file)

Description

Determine a directory's real path from the classpath.

License

Open Source License

Parameter

Parameter Description
cls The class.
file A file inside that directory/.

Return

The directory path.

Declaration

public static String findDirectoryFromClasspath(Class<?> cls, String file) 

Method Source Code

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

import java.io.File;

import java.net.URL;

public class Main {
    /**/*w w  w  . j a v a  2s  . c  om*/
     * Determine a directory's real path from the classpath.
     * 
     * @param cls The class.
     * @param file A file inside that directory/.
     * @return The directory path.
     */
    public static String findDirectoryFromClasspath(Class<?> cls, String file) {
        URL rootMarker = cls.getResource(file);
        String markerPath = rootMarker.getPath();
        File markerFile = new File(markerPath);
        return markerFile.getParentFile().getAbsolutePath() + "/";
    }
}

Related

  1. fillClassPath(ClassLoader cl, StringBuffer classpath)
  2. findClassPaths()
  3. findClassPaths()
  4. findClasspathsByLoader(ClassLoader loader)
  5. findClassPathsToEn()
  6. findResourceOnClasspath(String resourceName)
  7. getAvailableClassPathInfo(final ClassLoader classLoader)
  8. getBootstrapClassPath()
  9. getDriverClassLoader(String driverClasspath)