How do I make a java.io.File into a java.lang.Class to run it?

I have a program that lets a user select any .class or .jar file and run it. The problem is that, to run it, I need to use something other than a java.io.File, which is what a JFileChooser returns. How can I make a java.io.File into a java.lang.Class or java.util.jar.JarFile?

Answers


If you have a File object of the class you want to load, you can use a URLClassLoader to load the class. The File object can provide the URL.


Need Your Help

Is it possible to declare a variable as “always global”?

php global-variables global

Is there any way I can define a variable such a way that I don't need to global $var1; in every function? Just define it in beginning and keep using where ever needed. I know $GLOBALS exist, but do...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.