我正在unziping一个基于官方文档和一些例子的文件。我目前的实现将该文件解压缩到zip文件所在的同一目录中。我想解压到设备中的特定目录。我怎样才能做到这一点? ZipInputStream允许这个功能,还是我必须解压缩,然后将文件移动到所需的文件夹?如何解压缩文件在Android中执行特定的文件夹?
这是我的代码:
public static boolean unpackZip(String path, String zipname) {
InputStream is;
ZipInputStream zis;
try {
String filename;
is = new FileInputStream(path + zipname);
zis = new ZipInputStream(new BufferedInputStream(is));
ZipEntry ze;
byte[] buffer = new byte[1024];
int count;
while ((ze = zis.getNextEntry()) != null) {
filename = ze.getName();
if (ze.isDirectory()) {
File fmd = new File(path + filename);
fmd.mkdirs();
continue;
}
FileOutputStream fout = new FileOutputStream(path + filename);
while ((count = zis.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
fout.close();
zis.closeEntry();
}
zis.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}