Java Resource Path Get getResources(String path, ClassLoader loader)

Here you can find the source of getResources(String path, ClassLoader loader)

Description

get Resources

License

Open Source License

Declaration

protected static Enumeration<URL> getResources(String path, ClassLoader loader) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;
import java.net.URL;

import java.util.*;

public class Main {
    protected static Enumeration<URL> getResources(String path, ClassLoader loader) throws IOException {
        // make sure the class loader isn't null
        if (loader == null) {
            //             log.debug("No loader for get resource request", "path", path);
            return null;
        }//from  w w w. jav a2s.co  m
        // try the path as is
        Enumeration<URL> enm = loader.getResources(path);
        if (enm.hasMoreElements()) {
            return enm;
        }
        // try toggling the leading slash
        return loader.getResources(togglePath(path));
    }

    protected static String togglePath(String path) {
        if (path.startsWith("/")) {
            return path.substring(1);
        } else {
            return "/" + path;
        }
    }
}

Related

  1. getResourcePath(String name)
  2. getResourcePath(String path)
  3. getResourcePath(String resource)
  4. getResourcePath(String resource)
  5. getResources(ClassLoader cl, String resourcePath)
  6. getResources(String resourcePath, Class caller)
  7. getResourceStream(final String bundle, final String path)
  8. getResourceStream(String path)
  9. getStringFromResource(Class clazz, String path)