TypeA.class位于classpath下, /absolute_path/TypeA.class为其在文件系统中的绝对路径,
且类文件小于1k, MyClassLoader为一个自定义的类加载器, 下面的这段类加载程序是否正确, 如果有错请指出哪一行有错, 简述理由。
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
public class Tester{
public static void main(String[] args){
MyClassLoader cl1=new MyClassLoader();
try{
File f=new File("/absolute_path/TypeA.class");
byte[] b=new byte[1024];
InputStream is=new FileInputStream(f);
int I=is.read(b);
Class c=cl1.defineMyClass(null,b,0,1);
TypeA a=(TypeA)c.newInstance();
}catch(Exception e){
e.printStacktrace();
}
}
}