I'm writing a java program that works with .class files. I want to be able to read a .class file on the filesystem (with InputStream) and determine the package that it is in. That .class file might not be in a nice package directory structure, it could be lying around in some random place. How can I do this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Read the class file format documentation - or use a library which knows how to parse class files, such as BCEL and its ClassParser
class.