I have the following code that retrieves a list of files from a folder and in my for statement i want to compare them to see do the names match
Class classFile = null;
// Retrieve the java file
final File javaFolder = new File(filePath);
// Retrieves all the class files
List<Class> classFiles = new ArrayList<>();
final File classFolder = new File(compileFile.getDirectoryForBin());
classFiles = retrieveFiles.listClassFilesForFolder(classFolder);
// compared the java files to the class files and add the correct files to the list
for (Class currentClassFile : classFiles) {.....}
Im getting the following error
java.lang.ClassCastException: java.io.File cannot be cast to java.lang.Class
at Java.OrganisingFiles.getClasses(OrganisingFiles.java:129)
This is because i have a list of files that cannot be cast to Class in my for loop. Does anybody know how to convert a File to a Class type or is it better to just to cast all the files as objects as java.lang.Class is a subclass of java.lang.Object?
Class? From your loop it looks like you'll only need to compare file names?Files