尝试将所有文件连接到一个文件中,然后提取单个文件。就像是:
File dir = new File("D:/arc");
FileOutputStream fos = new FileOutputStream(new File(
"d:/arc/archieve-full.zip"));
FileInputStream fis = null;
Set<String> files = new TreeSet<String>();
for (String fname : dir.list()) {
files.add(fname);
}
for (String fname : files) {
try {
fis = new FileInputStream(new File(dir.getAbsolutePath(), fname));
byte[] b = new byte[fis.available()];
fis.read(b);
fos.write(b);
} finally {
if (fis != null) {
fis.close();
}
fos.flush();
}
}
fos.close();
ZipFile zipFile = new ZipFile("d:/arc/archieve-full.zip");
/*extract files from zip*/
更新:使用 aTreeSet
对文件名进行排序,因为dir.list()
不保证字母顺序。