Need a way to get class file objects from JAR File

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Need a way to get class file objects from JAR File

  1. #1
    Join Date
    Oct 2008

    Need a way to get class file objects from JAR File

    Hi, I need a way to get class files (File objects) from a JAR file (unknown JAR file).

    I know that you cant acutally get the File objects from the JAR itself (only get inputstreams from each entry). So i guess i need a way to use the input stream to create a temp file that is the actual .class file so I can get a File object for it.

    Once i have this i can use it as I want then delete it and go to the next one.

    I dont know if there is an easier or more efficient way?

    The reason I need the actual File object is that im using a Library that requires a File object of a class file to do its function.

    Anyways I have the incomplete code here:

    Enumeration <JarEntry> e;
    		JarFile jf = new JarFile("C:\\ToDoList_1.0.0.jar");
    		e = jf.entries();
    			JarEntry entry = new JarEntry(e.nextElement());
    			String name = entry.getName();
    			if((name.length() >4) && (name.substring(name.length()-5, name.length()).equalsIgnoreCase("class"))){
    				InputStream input = jf.getInputStream(entry);
    So im looking for some help on how to create a file, THen i guess read in the bytes from the InputStream and write them out to the new file. Is this possible? Please any help would be great.

  2. #2
    Join Date
    Jul 2005
    SW MO, USA
    A way to get a File object would be to override/extend the File class and write your own versions of the methods that the library routines call to redirect the input to come from the jar file vs from a disk file.

  3. #3
    Join Date
    Nov 2008
    Hi mcnkevin,

    I am facing the same problem....Can you please tell me the solution if you have got it?


Similar Threads

  1. Initialize class in jsp file
    By major in forum Java
    Replies: 0
    Last Post: 05-12-2007, 05:27 PM
  2. Problems with URI in a jar file
    By alcdotcom in forum Java
    Replies: 4
    Last Post: 09-29-2005, 08:09 PM
  3. How to read objects from file in a loop
    By mail2vinaybabu in forum Java
    Replies: 10
    Last Post: 02-27-2005, 01:07 PM
  4. Replies: 1
    Last Post: 02-05-2001, 10:11 PM
  5. file name==class name. why?
    By siva in forum Java
    Replies: 2
    Last Post: 01-03-2001, 10:40 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center