Java Resource Load getResourceFile(String resource)

Here you can find the source of getResourceFile(String resource)

Description

Try to discover the File for the test resource

License

Open Source License

Declaration

public static File getResourceFile(String resource) 

Method Source Code


//package com.java2s;
import java.io.File;

public class Main {
    private static final String SYSPROP_TEST_RESOURCES_DIRECTORY = "test.resources.directory";
    private static final String testResourcesDir = System.getProperty(SYSPROP_TEST_RESOURCES_DIRECTORY);

    /** Try to discover the File for the test resource */
    public static File getResourceFile(String resource) {
        File file = new File(resource);
        if (file.exists())
            return file;

        file = new File(getTestResourcesDir() + "/" + resource);
        if (file.exists())
            return file;

        String notSet = (getTestResourcesDir() == null
                ? " System property '" + SYSPROP_TEST_RESOURCES_DIRECTORY + "' not set."
                : "");
        throw new IllegalArgumentException(
                "Cannot obtain '" + getTestResourcesDir() + "/" + resource + "'." + notSet);
    }//from   w w w .  j  a  v  a  2  s . c o  m

    public static String getTestResourcesDir() {
        return testResourcesDir;
    }
}

Related

  1. getResourceByZip(final ZipInputStream zipIN, final String resourcePath)
  2. getResourceDirectory()
  3. getResourceFile(Class clazz, String path)
  4. getResourceFile(Class theClass, String fileName)
  5. getResourceFile(String relativeResourceFilePathname)
  6. getResourceFile(String resourceName)
  7. getResourceFromJar(File fromFile, String insideFile)
  8. getResourceInDirPackage(String packageName, String packagePath, final boolean recursive, List classes)
  9. getResourceList(File fdir, String extn)