Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java extract zip

        String sourceFile = "test1.txt";
        FileOutputStream fos = new FileOutputStream("compressed.zip");
        ZipOutputStream zipOut = new ZipOutputStream(fos);
        File fileToZip = new File(sourceFile);
        FileInputStream fis = new FileInputStream(fileToZip);
        ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
        zipOut.putNextEntry(zipEntry);
        byte[] bytes = new byte[1024];
        int length;
        while((length = fis.read(bytes)) >= 0) {
            zipOut.write(bytes, 0, length);
        }
        zipOut.close();
        fis.close();
        fos.close();
Comment

java extract zip


import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.core.ZipFile;


public static void unzip(){
    String source = "some/compressed/file.zip";
    String destination = "some/destination/folder";
    String password = "password";

    try {
         ZipFile zipFile = new ZipFile(source);
         if (zipFile.isEncrypted()) {
            zipFile.setPassword(password);
         }
         zipFile.extractAll(destination);
    } catch (ZipException e) {
        e.printStackTrace();
    }
}

Comment

PREVIOUS NEXT
Code Example
Java :: public static void main vs static public void main 
Java :: java regex 
Java :: android kill other app programmatically by package 
Java :: java string array initialization 
Java :: set source image in android studio 
Java :: intent android 
Java :: datatypes in java 
Java :: intent in java 
Java :: find maximum in array java 
Java :: flutter java.lang.RuntimeException: Unable to instantiate activity ComponentInfo 
Java :: Java NoClassDefFoundError but class is there 
Java :: java array add element 
Java :: how to convert primitive int to Integer in java 
Java :: armstrong number in java 
Java :: Java push() Method 
Java :: java wait(timeout) 
Java :: execute exe java 
Java :: programmatically click button javafx 
Java :: java substring after last char 
Java :: Java How to use SortedSet? 
Java :: I/flutter (10109): {filePath: null, errorMessage: java.io.FileNotFoundException: open failed: EACCES (Permission denied), isSuccess: false} 
Java :: reviews button ade android studio 
Java :: HttpContext.GetOwinContext().Authentication.SignOut 
Java :: pyramid pattern program in java 
Java :: set view size android 
Java :: how to multiply bigdecimals 
Java :: get key from value hashmap 
Java :: integer.tobinarystring returns 
Java :: java arraylist remove 
Java :: fastreader in java 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =