Java Resource Load getResourceAsFile(String resourceName)

Here you can find the source of getResourceAsFile(String resourceName)

Description

get Resource As File

License

Apache License

Declaration

public static File getResourceAsFile(String resourceName) 

Method Source Code


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

import java.io.File;

public class Main {
    public static File getResourceAsFile(String resourceName) {
        return new File(Thread.currentThread().getContextClassLoader().getResource(stripLeadingSlash(resourceName))
                .getFile().replaceAll("%20", " "));
    }//from   ww w  .  j  av a  2  s . c  om

    private static String stripLeadingSlash(String resourceName) {
        return (resourceName.startsWith("/")) ? resourceName.substring(1) : resourceName;
    }
}

Related

  1. getResourceAsBytes(Class testClass, String resourceName)
  2. getResourceAsBytes(ClassLoader classLoader, String resourcePath)
  3. getResourceAsBytes(String path, ClassLoader loader)
  4. getResourceAsBytes(String url)
  5. getResourceAsFile(String path)
  6. getResourceAsFile(String resourcePath)
  7. getResourceAsFile(T testSuite, String resourceName)
  8. getResourceAsInputStream(Class resourceClass, String resourceName)
  9. getResourceAsProperties(String resource)