Java Class Loader getFileFromClassLoader(String fileName)

Here you can find the source of getFileFromClassLoader(String fileName)

Description

Helper method which gets a file using the current class loader.

License

Apache License

Parameter

Parameter Description
clazz Class.
fileName Name of file.

Return

file object or null if none.

Declaration

public static File getFileFromClassLoader(String fileName) 

Method Source Code


//package com.java2s;
//LICENCE-START/*from   w  w w. j  ava2 s  .  c om*/

import java.io.File;
import java.net.URL;

public class Main {
    /**
     * Helper method which gets a file using the current class loader.
     * 
     * @param clazz
     *            Class.
     * @param fileName
     *            Name of file.
     * @return file object or <code>null</code> if none.
     */
    public static File getFileFromClassLoader(String fileName) {
        URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
        File file = null;
        if (url != null) {
            file = new File(url.getFile());
        }
        return file;
    }
}

Related

  1. getClassLoaders(ClassLoader baseClassLoader)
  2. getClassLoaderStack(ClassLoader cl)
  3. getClassLocation(Class clazz)
  4. getClassLocation(String className)
  5. getCustomClassloader(List entries)
  6. getFilesByPackgeName(String packageName, File _file, ClassLoader classLoader, List list)
  7. getJvmExtClassLoader()
  8. getLoadingDir(Class clazz)
  9. getManifest(ClassLoader cl, String extension)