How do I read a zip file over the network from a URL through a ZipInputStream?

Bogdan Sheptunov

This piece uncompresses every entry of a ZIP file and puts them into a Vector.

ZipEntry anEntry = null; 
Vector entriesList = new Vector(); 
try 
{ 
    URL aURL = new URL ("http://localhost/wwwroot.zip"); 
    URLConnection aConnection = aURL.openConnection(); 
    aConnection.setDoInput(true); 
    aConnection.setDoOutput(false); 
    aConnection.setUseCaches (false); 
    aConnection.setDefaultUseCaches (false); 
    aConnection.connect(); 
    ZipInputStream inputStream = new ZipInputStream(aConnection.getInputStream()); 
    anEntry = inputStream.getNextEntry(); 
    while (anEntry != null) 
    { 
        long decompressedSize = anEntry.getSize(); 
        byte[] uncompressedBuf = new byte[(int)decompressedSize]; 
        inputStream.read(uncompressedBuf); 
        entriesList.add(uncompressedBuf); 
        anEntry = inputStream.getNextEntry(); 
    } 
    inputStream.close(); 
} 
catch (Exception e) 
{ 
    System.out.println("Oops: " + e.getMessage()); 
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


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

 

 

About | Sitemap | Contact