Java Resource Get getResourceAsFile(Class klass, String resource)

Here you can find the source of getResourceAsFile(Class klass, String resource)

Description

Retrieves the file corresponding to the class resource

License

Contributor Agreement License

Parameter

Parameter Description
klass a parameter
resource resource name relative to class

Return

file that can be opened and used to read resource

Declaration

public static File getResourceAsFile(Class klass, String resource) 

Method Source Code


//package com.java2s;
/*//from w  ww. j a va  2  s.co  m
 *
 *
 * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement.
 * Contributors retain copyright to elements licensed under a Contributor Agreement.
 * Licensed to the User under the LGPL license.
 *
 * $
 */

import java.io.File;

import java.net.URL;

public class Main {
    /**
     * Retrieves the file corresponding to the class resource
     *
     * @param klass
     * @param resource resource name relative to class
     * @return file that can be opened and used to read resource
     */
    public static File getResourceAsFile(Class klass, String resource) {
        URL url = klass.getResource(resource);
        return new File(url.getFile());
    }
}

Related

  1. getResource(String res)
  2. getResource(String resource, Class context)
  3. getResourceAsBytes(String resource)
  4. getResourceAsBytes(String resource)
  5. getResourceAsFile(Class clazz, String resource)
  6. getResourceAsFile(Class sourceClass, String reference)
  7. getResourceAsFile(Class clazz, String fn)
  8. getResourceAsFile(Class clazz, String name)
  9. getResourceAsFile(Class clazz, String rscName)