Results 1 to 2 of 2
- 08-01-2007, 02:56 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 36
- Rep Power
- 0
How to load binary content of a .class file
when given the name of a class, I want to retrieve the binary content of the .class file. I have written the following sample but it does not work.
Can anyone help to find what is wrong with my sample?
Java Code:String className = this.getClass().getName(); InputStream inputStream = this.getClass().getResourceAsStream (className);
When executing the above code, the input Stream is always returned as "null".
Thanks
- 08-03-2007, 06:21 PM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 164
- Rep Power
- 6
The name of the file containing the bytecode is not the same as the classname, but it has a suffix ".class". Furthermore, a classname as returned by Class.getName() returns the fully qualified name, including the package, with "." as the separation between the parts. That will probably not be a valid filename (I can think only of z/OS as an OS that uses the period as a separator char), since you're looking for that file on the filesystem. Replace the "." with the File.separator string and you should be set.
Similar Threads
-
How to Save/Load Vector to/from file
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:37 PM -
Reading a Field in a Binary File
By janakiram.attuluri in forum Advanced JavaReplies: 2Last Post: 01-09-2008, 10:47 AM -
reading a binary file with a RAF
By jkurth in forum Advanced JavaReplies: 2Last Post: 12-20-2007, 07:30 AM -
how to load a file in remote machine
By christina in forum New To JavaReplies: 1Last Post: 08-06-2007, 09:33 PM -
how to load a java class in startup
By leonard in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 03:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks