集册 Java实例教程 在目录中查找类

在目录中查找类

欢马劈雪     最近更新时间:2020-01-02 10:19:05

411
在目录中查找类


//package com.nowjava;

import java.io.File;
/*n o w j a v a . c o m*/

import java.util.List;


public class Main {



    private static void findClassInDir(File directory, String packageName,

            List<Class<?>> classes, boolean annotated)

            throws ClassNotFoundException {

        File[] files = directory.listFiles();

        for (File file : files) {

            if (file.isDirectory()) {

                assert !file.getName().contains(".");

                findClassInDir(file, packageName + "." + file.getName(),

                        classes, annotated);

            } else if (file.getName().endsWith(".class")) {

                Class<?> clazz = Class.forName(packageName
                /*
                时   代     Java  公  众  号 - nowjava.com 提 供
                */

                        + '.'

                        + file.getName().substri
展开阅读全文