s";
// String[] fqnArr = name.split("\\."); // split("."); 是不行的, 必须split("\\.")
// if (fqnArr == null || fqnArr.length == 0) {
// System.out.println("ClassLoaderLK.findClass()");
// fqnArr = name.split("\\.");
// } else {
// System.out.println( name + fqnArr.length);
// }
String classFile = path + classPath;
byte[] data = getClassFileBytes(classFile );
class1 = defineClass(name, data, 0, data.length);
if (class1 == null) {
System.out.println("ClassLoaderLK.findClass() ERR ");
throw new ClassFormatError();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return class1;
}
private byte[] getClassFileBytes(String classFile) throws Exception {
FileInputStream fis = new FileInputStream(classFile );
FileChannel fileC = fis.getChannel();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel outC = Channels.newChannel(baos);
ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
while (true) {
int i = fileC.read(buffer);
if (i == 0 || i == -1) {
break;
}
buffer.flip();
outC.write(buffer);
buffer.clear();
}
fis.close();
return baos.toByteArray();
}
}
package com.