Hey, I think the title sums it, but still.
I need to extract the fully qualified name of an object from its compiled .class file, could anyone point me in the right direction?
Thanks,
Adam.
A fully-qualified class name in Java contains the package that the class originated from. Also, an inner class is a class that is another class member. So, the fully-qualified name of an inner class can be obtained using the getName() method.
The term fully qualified file name (or FQFN) means a file on a computer whose exact name is completely specified such that it is unambiguous and cannot be mistaken for any other file on that computer system.
Press Ctrl + Alt + Shift + C (Edit | Copy Reference) on "Editor" in the code and you'll have the fully-qualified name in your clipboard. Or alternatively just right-click on the code and select "Copy Reference".
The fully qualified name of the type "array of array of array of array of String " is "java. lang. String[][][][] ".
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();
}
getClass().getName()
Update: You can load the class-file into a byte[]
(using standard i/o) and then use getClass().getClassLoader().defineClass(...)
Use a library like BCEL to read the classfile into memory and query it for the class name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With