File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes class file bytes from Class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "class file bytes from Class?" Watch "class file bytes from Class?" New topic

class file bytes from Class?

Mani Venkatesan
Ranch Hand

Joined: Sep 15, 2002
Posts: 64
Is there a way in which I can get the byte code of a class from its corresponding java.lang.Class object?

thanks in advance,

Mani<br /><a href="" target="_blank" rel="nofollow">blog</a>
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Open the class file as a FileInputStream and read the data into a byte[].


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Mani Venkatesan
Ranch Hand

Joined: Sep 15, 2002
Posts: 64
I do not know where the class file is. I have an application sitting inside a JVM and the application is a class file transformer that is fed classes from outside.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 692
Is the class file on the classpath? You could use getResource() to get a URL to the file that you could then read from.
I agree. Here's the link:
subject: class file bytes from Class?
It's not a secret anymore!