• Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamically create a file & load it using Class.forName()  RSS feed

 
Vincent Goh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

thanks,
vincent

-------------------------------------------------------------------------
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!