java类加载文章
作者:互联网
(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();
}
}
标签:java,bs,length,文章,close,byte,加载,bis,cls 来源: https://www.cnblogs.com/dronff/p/16552747.html