Java ZIP - 如何解压缩文件夹? [英] Java ZIP - how to unzip folder?
问题描述
是否有任何示例代码,如何将文件夹从 ZIP 部分解压缩到我想要的目录中?我已将文件夹FOLDER"中的所有文件读入字节数组,如何从其文件结构重新创建?
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?
推荐答案
我不知道你说的部分是什么意思?您的意思是在没有 API 帮助的情况下自己做吗?
I am not sure what do you mean by particaly? Do you mean do it yourself without of API help?
如果你不介意使用一些开源库,有一个很酷的 API 叫做 zip4J
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();
}
我希望这是有用的.
这篇关于Java ZIP - 如何解压缩文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!