dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Jan 9, 2007

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Read Entries from JAR/ZIP Archives with the URL Class

This tip shows you how to display the entries from a JAR/ZIP archive using the java.net.URL class. The key of the example is the URL construction.

import java.net.*;
import java.io.*;
import java.awt.*;
import java.util.*;
import java.util.jar.*;

class read extends Frame
{
   URL url=null;
   JarURLConnection URLcon=null;
   JarFile jar=null;
   TextArea TA=new TextArea(15,35);

   public read(String titlu)
   {
      super(titlu);
   }

   void init()
   {
      setLayout(new FlowLayout());
      setSize(300,300);
      add(TA);
      setVisible(true);
   }

   public void getURLContent()
   {   
      try
      {
         //local archive
         url=new URL("jar:file:/C:/Program%                  
            20Files/Java/jdk1.5.0/jre/lib/jsse.jar!/");
         //remote archive
         //url=new URL("jar:http://.../archive.jar!/");
                
         URLcon=(JarURLConnection)(url.openConnection());
         jar=URLcon.getJarFile();
      }
      catch(MalformedURLException e)
      {
         System.out.println("Eroare1:"+e.getMessage());
      }
      catch(IOException e)
      {
         System.out.println("Eroare2:"+e.getMessage());
      }
   }
 
  void entry()
   {
      Enumeration <JarEntry> entries=jar.entries();
      while(entries.hasMoreElements())
      {
         String entryJarEntry)entries.nextElement()).getName();
         TA.append(entry+"\n");
      }  
   }
}

public class JarURLContent{
   public static void main(String[] args)
   {
       read t=new read("URL");      
       t.getURLContent();
       t.init();    
       t.entry();  
   }
}
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date