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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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="http://ideanimal.com" 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: 685
Is the class file on the classpath? You could use getResource() to get a URL to the file that you could then read from.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: class file bytes from Class?
Similar Threads
call base class method
a problem with running the servlet
what is the replace method for getBinaryOutputStream() ?
Converting a Base64 encoded String to an Image