I was following an example from the following link:
http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html?page=1 and this is an output I am getting:
This program will use SimpleClassLoader. >>>>>> Load class : TestClass >>>>>> Not a system class. >>>>>> Fetching the implementation of TestClass file was read successfully Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 1768779887 in class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at aha.SimpleClassLoader.loadClass(SimpleClassLoader.java:80) at aha.SimpleClassLoader.loadClass(SimpleClassLoader.java:42) at aha.Example.main(Example.java:11)
here is an example of my method that reads a file:
private byte getClassImplFromDataBase(String className)[] {
System.out.println(" >>>>>> Fetching the implementation of "+className);
byte result[];
try {
FileInputStream fi = new FileInputStream("C:/delete/"+className+".impl");
result = new byte[fi.available()];
fi.read(result);
System.out.println("file was read succesfullyl");
return result;
} catch (Exception e) {
/*
* If we caught an exception, either the class wasnt found or it
* was unreadable by our process.
*/
return null;
}
}
I placed TestClass.impl file under C:/delete directory . My classes reside under package: aha So the file TestClass.impl is read ok, but something happens during the result = defineClass(classData, 0, classData.length); I know this method is deprecated but still ??