Java Resource Get getResourceAsFile(Class clazz, String fn)

Here you can find the source of getResourceAsFile(Class clazz, String fn)

Description

Get a file to read the raw contents of the given resource :)

License

Open Source License

Declaration

public static File getResourceAsFile(Class<?> clazz, String fn) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

import java.net.URL;

public class Main {
    /** Get a file to read the raw contents of the given resource :) */
    public static File getResourceAsFile(Class<?> clazz, String fn) throws IOException {
        URL url = clazz.getResource(fn);
        if (url == null || url.getFile() == null) {
            throw new IOException("resource \"" + fn + "\" relative to " + clazz + " not found.");
        }// w ww.j  a  v  a  2 s. co m
        return new File(url.getFile());
    }
}

Related

  1. getResourceAsBytes(String resource)
  2. getResourceAsBytes(String resource)
  3. getResourceAsFile(Class clazz, String resource)
  4. getResourceAsFile(Class klass, String resource)
  5. getResourceAsFile(Class sourceClass, String reference)
  6. getResourceAsFile(Class clazz, String name)
  7. getResourceAsFile(Class clazz, String rscName)
  8. getResourceAsFile(final Class clazz, final String name)
  9. getResourceAsFile(final String filename, final Class theClass)