Java ClassPath Get getClassPathFile(String pathName)

Here you can find the source of getClassPathFile(String pathName)

Description

get Class Path File

License

Apache License

Declaration

public static File getClassPathFile(String pathName) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.IOException;

import java.net.URL;

public class Main {
    public static File getClassPathFile(String pathName) throws Exception {
        // In windows, pathnames with spaces are returned as %20
        if (pathName.indexOf("%20") != -1)
            pathName = pathName.replaceAll("%20", " ");
        File tmp = new File(getResourceURL(pathName).getFile());
        return tmp;
    }//from   w w w .  ja v  a  2 s  . co m

    public static URL getResourceURL(String resource) throws IOException {
        URL url = null;
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader != null)
            url = loader.getResource(resource);
        if (url == null)
            url = ClassLoader.getSystemResource(resource);
        if (url == null)
            throw new IOException("Resource " + resource + " was not found");
        return url;
    }
}

Related

  1. getClasspathFile(Class clz)
  2. getClassPathFile(Class clazz)
  3. getClasspathFile(final String name)
  4. getClassPathFile(final String path, final ClassLoader classLoader)
  5. getClasspathFile(String fn)
  6. getClasspathFilePathFromName(String fileName)
  7. getClassPathFor(final Class clazz)
  8. getClasspathForClass(Class targetClass)
  9. getClassPathFromString(String classpath)