简体   繁体   中英

How to download and extract a ZIP file in Java

Ok so I am making a program that I want to look professional, so I'm making an installer for it. What I want to do is make a file on say mediafire or my website and it be a ZIP file. Now what I want to do is extract the folder in the ZIP file to my Program File (x86). How would I do this?

I was looking into the same thing not too long ago, have a look at zip4j . I found this answer from another poster here .

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();
    }
}

Probably you are looking for ZipInputStream. Try to look here :

http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM