是否有任何示例代码,如何将 ZIP 中的文件夹部分解压到我想要的目录中?我已将文件夹“FOLDER”中的所有文件读取到字节数组中,如何从其文件结构创建?
我不确定你所说的部分是什么意思?
您的意思是在没有 API 帮助的情况下自己完成吗?
如果您不介意使用一些开源库,
有一个很酷的 API 叫做zip4J http://www.lingala.net/zip4j/
它很容易使用,我认为对此有很好的反馈。
看这个例子:
String source = "folder/source.zip";
String destination = "folder/source/";
try {
ZipFile zipFile = new ZipFile(source);
zipFile.extractAll(destination);
} catch (ZipException e) {
e.printStackTrace();
}
如果您要解压的文件有密码,您可以尝试以下操作:
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();
}
我希望这有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)