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


Tip of the Day
Language: Java
Expertise: Intermediate
Nov 8, 2005

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Extract JAR and ZIP Entries with JarURLConnection

Use the following code to extract JAR and ZIP Entries with JarURLConnection:

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 file
      //url=new URL(
      //"jar:file:/C:/Program%20Files/Java/jdk1.5.0/jre/lib/jsse.jar!/"
      //);
      //remote file
      url=new URL(
        "jar:http://sosnoski.com/opensrc/xmlbench/code/xmlbench.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  entries=jar.entries();
   while(entries.hasMoreElements())
   {
      String entry=((JarEntry)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
Thanks for your registration, follow us on our social networks to keep up-to-date