A URLClassLoader can be used to load classes in any directory.
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
publicclass Main {
publicstaticvoid main(String[] argv) throws Exception {
File file = newFile("c:\\");
URL url = file.toURI().toURL();
URL[] urls = new URL[] { url };
ClassLoader cl = new URLClassLoader(urls);
Class cls = cl.loadClass("com.mycompany.MyClass");
}
}