如何在Java中查找类文件的包 [英] How to find the package of a class file in java

查看:69
本文介绍了如何在Java中查找类文件的包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个与.class文件一起使用的Java程序.我希望能够读取文件系统上的.class文件(使用InputStream)并确定它所在的包.该.class文件可能不在一个不错的包目录结构中,它可能位于某个随机位置.我该怎么办?

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?

推荐答案

阅读类文件格式文档-或使用知道如何解析类文件的库,例如 ClassParser 类.

Read the class file format documentation - or use a library which knows how to parse class files, such as BCEL and its ClassParser class.

这篇关于如何在Java中查找类文件的包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆