• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class file bytes from Class?

 
Mani Venkatesan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open the class file as a FileInputStream and read the data into a byte[].

Cheers,
 
Mani Venkatesan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 744
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the class file on the classpath? You could use getResource() to get a URL to the file that you could then read from.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic