I'm fairley new to programming in general being a fresh IT graduate.

Some software I am developing needs to be able to compress a folder in to a .zip file and later extract it while maintaining its file structure.

I am able to do this but extracting the file takes far to long, a file that takes a few seconds for winzip to extract takes far longer in my app.

I've tried google and have failed to find the reason for this. My code is as follows:

public void unzipFolder( String startingZip, String destinationFolder ) {
		try {
			ZipFile zipFile = new ZipFile(startingZip);
			Enumeration< ? extends ZipEntry> zipCount = zipFile.entries();
			String dir = destinationFolder;
		
			while( zipCount.hasMoreElements() ) {
				ZipEntry item = (ZipEntry) zipCount.nextElement();
			
				if (item.isDirectory()) {
					File newdir = new File(dir + File.separator + item.getName());
					newdir.mkdir();
				} else {
					String newfilePath = dir + File.separator + item.getName();
					File newFile = new File(newfilePath);
					if (!newFile.getParentFile().exists()) {
						newFile.getParentFile().mkdirs();
					}
					InputStream is = zipFile.getInputStream(item);
					FileOutputStream fos = new FileOutputStream(newfilePath);
					int ch;
					while( (ch = is.read()) != -1 ) {
						fos.write(ch);
					}
					is.close();
					fos.close();
					}
			}
			zipFile.close();
		} catch (Exception e) {
			System.out.println(e);
		}
	}

Any help would be greatly appreciated ;p

Also sorry for the double post, laggy internet to blame :S

I just timed it, 38 seconds to compress 306 Mb to 121 MB but to decompress the same info it took 45 minutes!

Winrar took 24 seconds... :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.