Java Resource Get getResourceFile(Class clazz, String fileName)

Here you can find the source of getResourceFile(Class clazz, String fileName)

Description

get Resource File

License

Open Source License

Declaration

public static File getResourceFile(Class clazz, String fileName) throws IOException, URISyntaxException 

Method Source Code


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

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    public static File getResourceFile(Class clazz, String fileName) throws IOException, URISyntaxException {
        ClassLoader classLoader = clazz.getClassLoader();
        URL resource = classLoader.getResource(fileName);
        if (resource == null)
            throw new FileNotFoundException(fileName + " not found");
        return new File(resource.toURI());
    }/* w w w.  j  a v  a  2s.  co m*/
}

Related

  1. getResourceBase()
  2. getResourceBundleLocaleString(String sKey, Object[] sParam, String sResourceBundle)
  3. getResourceContent(Object object, String resource)
  4. getResourceDir(final Class testClass)
  5. getResourceExpression(String select)
  6. getResourceFile(String name)
  7. getResourceFromBundle(Class clazz, String location)
  8. getResourceFromFile(String filename)
  9. getResourceInBundleOrFragments(Bundle bundle, String name)