ClassLoader loader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(filename));
ByteArrayOutputStream byteStr = new ByteArrayOutputStream();
int byt = -1;
while ((byt = in.read()) != -1) {
byteStr.write(byt);
}
byte byteArr[] = byteStr.toByteArray();
return defineClass(null, byteArr, 0, byteArr.length);
} catch (final RuntimeException rex) {
throw rex;
} catch (final Exception ex) {
ex.printStackTrace();
throw new ClassNotFoundException(name);
} finally {
if (in != null) {
try {
in.close();
} catch (final IOException ioe) {
ioe.printStackTrace();
}
}
}
}
};
loader.loadClass("garbage").newInstance();