lundi 20 juillet 2015

Load all classes in a specific folder without knowing package name - java

I have a code that load all classes in folder with same package name ( second ).

how can i change it to load all classes in a folder with deference package (not in second) (and we don't know the package name)

int classCounter = 0;

File folderAdded = new File("..//940424//second");
File [] classFileAdded = folderAdded.listFiles();
String [] addedClassName = new String [classFileAdded.length];
List<Operations> newOp = new ArrayList<Operations>();
Operations newOpTemp = null;

for(int i = 0; classCounter < classFileAdded.length; classCounter++){
    addedClassName [classCounter] = classFileAdded[classCounter].getAbsolutePath().substring(classFileAdded[classCounter].getAbsolutePath().lastIndexOf("\\")+1); 
    addedClassName [classCounter] = addedClassName[classCounter].substring(0,(addedClassName[classCounter].lastIndexOf(".")));
    addedClassName [classCounter] = "second." + addedClassName[classCounter];

    Class addedClass = Class.forName(addedClassName[classCounter]);
    }





Aucun commentaire:

Enregistrer un commentaire