自定义类加载器
public class ClassLoaderDIY extends ClassLoader{
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
System.out.println("自定义类加载器");
System.out.println(name);
//所有的.替换成\
name=name.replaceAll("\\.", "/");
System.out.println("替换后:"+name);
//根据name找到桌面上 相对应的 person.class文件
String desktopPath="C:\\Users\\Administrator\\Desktop\\"+name+".class";
System.out.println(desktopPath);
try {
FileInputStream fis=new FileInputStream(desktopPath);
System.out.println(fis.available());
int len=0;
byte[] b=new byte[fis.available()];
len=fis.read(b);
return defineClass(null,b,0,len);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}