我尝试了以下代码,但出现异常。有人可以帮我弄这个吗,
package defineClass;
import java.io.FileInputStream;
import java.io.IOException;
public class DefineClass extends ClassLoader {
static String PATH = "E:\\WorkSpaceOpkey\\tester\\src\\test2\\Bar.java";
public static void main(String[] m) throws IOException {
FileInputStream fis = new FileInputStream(PATH);
byte[] b = new byte[fis.available()];
fis.read(b);
new DefineClass().defineClass("test2.Bar", b, 0, b.length);
}
}
我在定义类时遇到以下错误
Exception in thread "main" java.lang.ClassFormatError: Incompatible magic
value 1885430635 in class file test2/Bar
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at defineClass.DefineClass.main(DefineClass.java:14)
繁星点点滴滴
相关分类