Package cn.edu. BNU. songjie. ch10.selfclassloader; import Java. io. *;/*** for a custom class loader, you only need to extend the classloader and overwrite its findclass (sring name) method. * This method is based on the class name specified by the parameter, returns the reference of the corresponding class object. * @ Author songjie **/public class myclassloader extends classloader {private string name; private string Path = "d :\\"; private final string filetype = ". class "; Public myclassloader (string name) {This. name = Name;} public myclassloader (classloader parent, string name) {super (parent); this. name = Name;} Public String tostring () {return name;} public void setpath (string path) {This. path = path;} Public String Getpath () {return path;} protected class findclass (string name) {byte [] DATA = loadclassdata (name); Return defineclass (name, Data, 0, Data. length ); // This method is inherited from classloader}/*** reads the second-level data of the class into the memory * @ Param name * @ return */private byte [] loadclassdata (string name) {fileinputstream FCM = NULL; byte [] DATA = NULL; bytearrayoutputstream baos = NULL; try {name = Name. replaceall ("\\. "," \\\\ "); FCM = new fileinputstream (New file (path + name + filetype); baos = new bytearrayoutputstream (); int CH = 0; while (CH = Fi. Read ())! =-1) {baos. write (CH);} DATA = baos. tobytearray ();} catch (filenotfoundexception E1) {system. out. println ("file not found");} catch (ioexception E2) {system. out. println ("File Content reading exception");} finally {try {baos. close (); FCM. close () ;}catch (ioexception E3) {e3.printstacktrace () ;}} return data ;}}