/** * <p>Title: TestFanShe.java</p> * <p>Description: </p> * <p>Company: www.treebear.cn</p> * @author chong.du * @date 2018年5月16日 * @version 1.0 */ package test.fanshe; import java.io.File; import java.net.URL; import java.util.Enumeration; import org.junit.Test; public class TestFanShe { @Test public void test() throws Exception { //包名 String packageName = "test.fanshe"; Enumeration<URL> urls = TestFanShe.class.getClassLoader().getResources(packageName.replace(".", "/")); while (urls.hasMoreElements()) { URL url = (URL) urls.nextElement(); if ("file".equals(url.getProtocol())) { String realPath = url.getFile(); File file = new File(realPath); if (file.exists()) { File[] files = file.listFiles(); for (File f : files) { System.out.println(f.getName()); } } } } } }