Here you can find the source of checkDirectory(File directory, String pckgname, ArrayList
Parameter | Description |
---|---|
directory | The directory to start with |
pckgname | The package name to search for. Will be needed for getting the Class object. |
classes | if a file isn't loaded but still is in the directory |
Parameter | Description |
---|---|
ClassNotFoundException | an exception |
private static void checkDirectory(File directory, String pckgname, ArrayList<Class<?>> classes) throws ClassNotFoundException
//package com.java2s; //License from project: Apache License import java.io.File; import java.util.ArrayList; public class Main { /**//from www . ja v a 2 s .com * Private helper method * * @param directory The directory to start with * @param pckgname The package name to search for. Will be needed for * getting the Class object. * @param classes if a file isn't loaded but still is in the directory * @throws ClassNotFoundException */ private static void checkDirectory(File directory, String pckgname, ArrayList<Class<?>> classes) throws ClassNotFoundException { File tmpDirectory; if (directory.exists() && directory.isDirectory()) { final String[] files = directory.list(); for (final String file : files) { if (file.endsWith(".class")) { try { classes.add(Class.forName(pckgname + '.' + file.substring(0, file.length() - 6))); } catch (final NoClassDefFoundError e) { // do nothing. this class hasn't been found by the // loader, and we don't care. } } else if ((tmpDirectory = new File(directory, file)).isDirectory()) { checkDirectory(tmpDirectory, pckgname + "." + file, classes); } } } } }