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());
				} else {
					String newfilePath = dir + File.separator + item.getName();
					File newFile = new File(newfilePath);
					if (!newFile.getParentFile().exists()) {
					InputStream is = zipFile.getInputStream(item);
					FileOutputStream fos = new FileOutputStream(newfilePath);
					int ch;
					while( (ch = is.read()) != -1 ) {
		} catch (Exception e) {

Any help would be greatly appreciated ;p

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... :(

This article has been dead for over six months. Start a new discussion instead.