Is there any sample code, how to particaly unzip folder from ZIP into my desired directory? I have read all files from folder "FOLDER" into byte array, how do I recreate from its file structure?
Methods. getComment(): String – returns the zip file comment, or null if none. getEntry(String name): ZipEntry – returns the zip file entry for the specified name, or null if not found. getInputStream(ZipEntry entry) : InputStream – Returns an input stream for reading the contents of the specified zip file entry.
I am not sure what do you mean by particaly? Do you mean do it yourself without of API help?
In the case you don't mind using some opensource library, there is a cool API for that out there called zip4J
It is easy to use and I think there is good feedback about it. See this example:
String source = "folder/source.zip"; String destination = "folder/source/"; try { ZipFile zipFile = new ZipFile(source); zipFile.extractAll(destination); } catch (ZipException e) { e.printStackTrace(); }
If the files you want to unzip have passwords, you can try this:
String source = "folder/source.zip"; String destination = "folder/source/"; String password = "password"; try { ZipFile zipFile = new ZipFile(source); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } zipFile.extractAll(destination); } catch (ZipException e) { e.printStackTrace(); }
I hope this is useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With