Results 1 to 2 of 2
  1. #1
    boy22 is offline Member
    Join Date
    Jul 2007
    Posts
    36
    Rep Power
    0

    Default 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

  2. #2
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    10

    Default

    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

  1. How to Save/Load Vector to/from file
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:37 PM
  2. Reading a Field in a Binary File
    By janakiram.attuluri in forum Advanced Java
    Replies: 2
    Last Post: 01-09-2008, 11:47 AM
  3. reading a binary file with a RAF
    By jkurth in forum Advanced Java
    Replies: 2
    Last Post: 12-20-2007, 08:30 AM
  4. how to load a file in remote machine
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:33 PM
  5. how to load a java class in startup
    By leonard in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 03:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •