(19条消息) 获取class类字节数组的方法_iteye_9747的博客-CSDN博客
public static byte[] loadBytes(Class<?> cls) throws IOException {
if (cls == null)
return null;
String name = cls.getCanonicalName().replaceAll("//.", "/") + ".class";
InputStream is = ClassLoader.getSystemResourceAsStream(name);
BufferedInputStream bis = new BufferedInputStream(is);
try {
int length = is.available();
byte[] bs = new byte[length];
System.err.println("ddd:" + bs.length);
bis.read(bs);
is.close();
return bs;
} finally {
bis.close();
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/278972.html