Extract Contents Of Zip File In Java Example

Chapter: ZIP Last Updated: 07-08-2017 15:36:24 UTC

Program:

            /* ............... START ............... */
                
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class JavaZipExtractContent {
	public static void main(String[] args) throws Exception {
		ZipInputStream inStream = new ZipInputStream(new FileInputStream("compressed.zip"));
		OutputStream outStream = new FileOutputStream("extracted.txt");

		byte[] buffer = new byte[1024];
		int read;
		ZipEntry entry;
		if ((entry = inStream.getNextEntry()) != null) {
			while ((read = inStream.read(buffer)) > 0) {
				outStream.write(buffer, 0, read);
			}
		}
		outStream.close();
		inStream.close();
	}
}
                /* ............... END ............... */
        

Notes:

  • ZipInputStream is the main class used for reading zip file and extracting files and directories.

Tags

Extract Contents Of A Zip File, Java

Similar Programs Chapter Last Updated
Zip Entry Is Directory Example In Java ZIP 23-04-2016
Create Zip File With CRC32 Checksum In Java ZIP 23-04-2016
Create Zip File With Adler32 Checksum In Java ZIP 23-04-2016
Extract Zip File With Adler32 Checksum In Java ZIP 23-04-2016
Extract File With CRC32 Checksum In Java ZIP 23-04-2016
CRC32 Checksum In Java ZIP 10-08-2016
Adler32 Checksum In Java ZIP 23-04-2016
Read Zip File Checksum Value In Java Example ZIP 20-07-2016
Create Checksum For Zip File In Java ZIP 07-08-2017
Decompress Zip File Using ZipInputStream In Java ZIP 20-07-2016
Read Entries In Zip File In Java Example ZIP 20-07-2016
List The Contents Of Zip File In Java Example ZIP 07-08-2017
Zip File Creation In Java Example ZIP 23-06-2016

1