Here you can find the source of getFilesByPackgeName(String packageName, File _file, ClassLoader classLoader, List
private static List<File> getFilesByPackgeName(String packageName, File _file, ClassLoader classLoader, List<File> list) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { public static List<File> getFilesByPackgeName(String packageName) throws IOException { return getFilesByPackgeName(packageName, null, Thread.currentThread().getContextClassLoader(), new ArrayList<File>()); }/*w ww . j a va 2 s . c om*/ private static List<File> getFilesByPackgeName(String packageName, File _file, ClassLoader classLoader, List<File> list) throws IOException { _file = _file != null ? _file : getPackageFolder(packageName, classLoader); if (_file != null) { File[] files = _file.listFiles(); for (File file : files) { if (file.isDirectory()) { if (!file.getName().contains(".")) getFilesByPackgeName(packageName + '.' + file.getName(), _file, classLoader, list); } else list.add(file); } } return list; } public static File getPackageFolder(String packageName) throws IOException { return getPackageFolder(packageName, Thread.currentThread().getContextClassLoader()); } private static File getPackageFolder(String packageName, ClassLoader classLoader) throws IOException { Enumeration<URL> resources = classLoader.getResources(packageName.replace('.', '/')); if (resources.hasMoreElements()) return new File(resources.nextElement().getFile()); return null; } }