I need a small code snippet which unzips a few files from a given .zip file and gives the separate files according to the format they were in the zipped file. Please post your knowledge and help me out.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
According to @zapl answer,Unzip with progress report:
The Kotlin way
Usage
->Helper Class(Unzipper.java)
->xml layout(activity_main.xml):
->permission in Menifest file:
I'm working with zip files which Java's ZipFile class isn't able to handle. Java 8 apparently can't handle compression method 12 (bzip2 I believe). After trying a number of methods including zip4j (which also fails with these particular files due to another issue), I had success with Apache's commons-compress which supports additional compression methods as mentioned here.
Note that the ZipFile class below is not the one from java.util.zip.
It's actually org.apache.commons.compress.archivers.zip.ZipFile so be careful with the imports.
For Gradle:
Password Protected Zip File
if you want to compress files with password you can take a look at this library that can zip files with password easily:
Zip:
Unzip:
Rar:
The documentation of this library is good enough, I just added a few examples from there. It's totally free and wrote specially for android.
Based on Vasily Sochinsky's answer a bit tweaked & with a small fix:
Notable differences
public static
- this is a static utility method that can be anywhere.File
parameters becauseString
are :/ for files and one could not specify where the zip file is to be extracted before. Alsopath + filename
concatenation > https://stackoverflow.com/a/412495/995891throws
- because catch late - add a try catch if really not interested in them.mkdirs()
is important.finally
to prevent resource leaks.So
should do the equivalent of the original