如果只需要类名,则可能自己解析类文件的开头,而不是仅仅为此目的而添加用于处理类代码的第三方库。您只需要常量池中的类和字符串,跳过访问标志,然后将/替换为即可。在班级名称中。如果有字节数组,则可以使用以下方法调用此方法
newByteArrayInputStream(byteArray):
public static String getClassName(InputStream is) throws Exception { DataInputStream dis = new DataInputStream(is); dis.readLong(); // skip header and class version int cpcnt = (dis.readShort()&0xffff)-1; int[] classes = new int[cpcnt]; String[] strings = new String[cpcnt]; for(int i=0; i<cpcnt; i++) { int t = dis.read(); if(t==7) classes[i] = dis.readShort()&0xffff; else if(t==1) strings[i] = dis.readUTF(); else if(t==5 || t==6) { dis.readLong(); i++; } else if(t==8) dis.readShort(); else dis.readInt(); } dis.readShort(); // skip access flags return strings[classes[(dis.readShort()&0xffff)-1]-1].replace('/', '.');}


