Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zip file not readable 1

Status
Not open for further replies.

SQL2KDBA69

Programmer
Feb 4, 2004
227
US
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
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();
		}
	}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top