如何读取.class文件的完全限定名称

Tac*_*0sS 7 java decompiling fully-qualified-naming .class-file

嘿,我认为标题总结了它,但仍然.

我需要从已编译的.class文件中提取对象完全限定名称,有人能指出我正确的方向吗?

谢谢,
亚当.

Boz*_*zho 12

getClass().getName()
Run Code Online (Sandbox Code Playgroud)

更新:您可以将类文件加载到byte[](使用标准i/o)然后使用getClass().getClassLoader().defineClass(...)


Ser*_*rov 5

public String getFullClassName(String classFileName) throws IOException {           
        File file = new File(classFileName);

        FileChannel roChannel = new RandomAccessFile(file, "r").getChannel(); 
        ByteBuffer bb = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int)roChannel.size());         

        Class<?> clazz = defineClass((String)null, bb, (ProtectionDomain)null);
        return clazz.getName();
    }
Run Code Online (Sandbox Code Playgroud)