import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class DemonstrationLoader extends ClassLoader { public Class findClass(String name) throws ClassNotFoundException { byte[] b= loadClassData(name); Class result= defineClass(name, b, 0, b.length); if (result == null) { throw new ClassNotFoundException(name); } return result; } private byte[] loadClassData(String name) { File f= getPath(name); long fileSize= (int) f.length(); if (fileSize > Integer.MAX_VALUE) throw new RuntimeException("too much bytecode"); int bytecodeSize= (int) fileSize; byte[] array= new byte[(int) bytecodeSize]; BufferedInputStream bis= null; try { FileInputStream fis= new FileInputStream(f); bis= new BufferedInputStream(fis); bis.read(array, 0, bytecodeSize); } catch (IOException e) { } finally { try { if (bis != null) bis.close(); } catch (IOException e) { } } return array; } static final String SEP= System.getProperty("file.separator"); public File getPath(String name) { return new File("." + SEP + "classes" + SEP + name + ".class"); } }