java code
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yue_Ke
Posted On:   Monday, February 10, 2003 02:00 PM

I don't know How to save the uncompressed file into a directory in the following cade. Can someboby help me? Thanks! 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) { lon   More>>

I don't know How to save the uncompressed file into a directory in the following cade. Can someboby help me?
Thanks!



			
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());

}
   <<Less

Re: java code

Posted By:   James_Bayer  
Posted On:   Monday, February 10, 2003 03:05 PM

it looks like you have a vector of byte arrays which all of the files in the zip.


try something like this, warning, this is untested...


...
while (anEntry != null)
{
long decompressedSize = anEntry.getSize();
byte[] uncompressedBuf = new byte[(int)decompressedSize];
inputStream.read(uncompressedBuf);
entriesList.add(uncompressedBuf);

//you may be able to add more path info here
FileOutputStream fos = new FileOutputStream( "c:\my\favorite\path\" + anEntry.getName() );
fos.write( uncompressedBuf, 0, uncompressedBuf.length );
fos.close();



anEntry = inputStream.getNextEntry();


}
inputStream.close();
About | Sitemap | Contact