I am able to retrieve a list of files from a directory using the following code
public List listClassFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listClassFilesForFolder(fileEntry);
} else {
if (fileEntry.toString().toUpperCase().endsWith(".CLASS")) {
filesInDirectory.add(fileEntry);
System.out.println(fileEntry.getName());
}
}
}
return filesInDirectory;
}
But i want to retrieve a list of java.lang.Classes (e.g. Example.class) so the above method does not work as it returns a list of java.io.Files.
Does anyone know a recursive method that can return a list of java.lang.Classes as i need to pass in a list of java.lang.Class and not java.io.Files?
Well. You need to load classes to get Class objects. To do that you either have to make sure those files are in your classpath and then Class.forName or then you will have to make your own classloader and load the file data and define a new class with the classloader.