Java Resource Get getResourcesFromDirectory(File resource, Pattern pattern)

Here you can find the source of getResourcesFromDirectory(File resource, Pattern pattern)

Description

get Resources From Directory

License

Open Source License

Declaration

private static List<URL> getResourcesFromDirectory(File resource, Pattern pattern) throws IOException 

Method Source Code


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

import java.io.*;

import java.net.URL;

import java.util.ArrayList;

import java.util.List;

import java.util.regex.Pattern;

public class Main {
    private static List<URL> getResourcesFromDirectory(File resource, Pattern pattern) throws IOException {
        ArrayList<URL> urls = new ArrayList<>();
        final File[] fileList = resource.listFiles();
        if (fileList == null)
            return urls;
        for (final File file : fileList) {
            if (file.isDirectory()) {
                urls.addAll(getResourcesFromDirectory(file, pattern));
            } else {
                final String fileName = file.getCanonicalPath();
                if (pattern.matcher(fileName).matches()) {
                    urls.add(new URL(resource + "/" + fileName));
                }//w  w  w .j av  a  2 s.  com
            }
        }
        return urls;
    }

    /**
     * Check if the argument is a directory.
     */
    public static boolean isDirectory(String dir) {
        return (new File(dir)).isDirectory();
    }
}

Related

  1. getResourceListing(ClassLoader cl)
  2. getResourceMessage(Locale locale, String resource, String key, Object... params)
  3. getResourceReader(Class clazz, String name, String charset)
  4. getResources(String archiveName)
  5. getResources(String pkgName)
  6. getResourceString(ResourceBundle rb, String key, Object param1)
  7. getResourceString(String key)
  8. getResourceString(String key, Object... args)
  9. loadResource(Class contextClass, String resourceName)