zoukankan      html  css  js  c++  java
  • 通过包名获取该包下的所有类

    /**  
    * <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());
    
    					}
    				}
    			}
    		}
    	}
    
    }
    

      

  • 相关阅读:
    软工实践4
    软工实践3
    软工实践1
    《暗时间》读书笔记
    关系规范化(数据库)
    关于Git的初步使用
    软件体系结构模式
    第六周编程总结
    第五周编程总结
    第四周编程总结
  • 原文地址:https://www.cnblogs.com/geekdc/p/9047686.html
Copyright © 2011-2022 走看看