vendredi 8 novembre 2019

Checking if file is in folder AND want to create a instance of that file if it exists

Hello fellow Stack users. So what i am trying to do is: 1. Take user input (that is supposed to be a file name) and check if that file exists in my current work folder. ( I DONT NEED HELP HERE, this is under control) 2. If the file exists, i want to create an instance of that file. (I wanna do this so i can use reflections and check if the file is a particular interface, and check the constructor.

So for testing my program, i created an instance of a existing file like this:

File tempFile = new File("/CURRENTFOLDER/" + file + ".java"); //with the user input tempFile = Test1.

    if(tempFile.exists()){

        Test1 test1 = new Test1();
        Class<?> test1_class = test1.getClass();

but what i really wanna do is something like this:

File tempFile = new File("CURRENTFOLDER" + file + ".java");

    if(tempFile.exists()){

        //Test1 test1 = new Test1();
        //Class<?> test1_class = test1.getClass();

        tempFile instance_of_tempFile = new tempFile();
        Class<?> ? test_class = instance_of_tempFile.getClass();

I know you cant write " tempFile instance_of_tempFile = new tempFile();", but just included that so you understand what im trying to do.





Aucun commentaire:

Enregistrer un commentaire