dynamically create a file & load it using Class.forName()
Vincent Goh
Greenhorn
Joined: Mar 06, 2007
Posts: 7
posted
0
I'm trying to dynamically create a file in the source directory. Then load the newly created code file using Class.forName();
The problem: when the file gets created, i wasn't able to see it until I do a refresh on the project. Which means that I have to relaunch the program in order to access the code file created. That's bad! Is there a way to create the code file then access it using Class.forName() without relaunching the program? Feel free to try out the code below.
Aren't you missing the step where you are compiling the source file? Class.forName can only load class file, not source files. Your IDE probably compiles it when you run the program, but that is not a function of Java itself. In you want to create new classes with a running program, you need to compile them explicitly.