Java Class Path getFile(Class base, String path)

Here you can find the source of getFile(Class base, String path)

Description

get File

License

Apache License

Declaration

@SuppressWarnings("rawtypes")
    public static File getFile(Class base, String path) 

Method Source Code


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

import java.io.File;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    @SuppressWarnings("rawtypes")
    public static File getFile(Class base, String path) {
        return urlToFile(base.getResource(path));
    }// w w w.  j a va2s. c o m

    public static File urlToFile(URL url) {
        if (url == null) {
            return null;
        }
        File file = null;
        try {
            file = new File(new URI(url.toExternalForm()));
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e.toString());
        }
        return file;
    }
}

Related

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