SQL2KDBA69
Programmer
it zips the directory but i cant unzip it with nothing tried winzip and winwar and both says it an invalid format.
so there got to be something wrong with my zip method. Thanks for any help
here is my code
so there got to be something wrong with my zip method. Thanks for any help
here is my code
Code:
void ZipDir( String strDir ) throws IOException, IllegalArgumentException
{
File dir = new File( strDir );
if( !dir.isDirectory() )
throw new IllegalArgumentException( strDir + "is not a directory" );
String[] zipEntries = dir.list();
byte[] dataBuffer = new byte[65536];
int byteRead;
ZipOutputStream zipOut = new ZipOutputStream( new FileOutputStream( "c:\\" + dir.getName() + ".zip" ) );
for( int i = 0; i < zipEntries.length; i++ )
{
File f = new File( dir, zipEntries[i] );
if( f.isDirectory() )continue;
FileInputStream fisIn = new FileInputStream( f );
ZipEntry zipEntry = new ZipEntry( f.getPath().substring( strDir.length() + 1 ) );
zipOut.putNextEntry( zipEntry );
while( ( byteRead = fisIn.read( dataBuffer ) )!= -1 )
{
zipOut.write( dataBuffer, 0, byteRead );
}
fisIn.close();
}
}