我有一个包含路径的 zip 文件。当我解压缩文件并将其放入目标文件夹时,它会创建路径的文件夹。
public boolean doZip(String fileName, String zipfilename) {
boolean zipStatus = true;
try {
String[] filesToZipP = new String[1];
filesToZipP[0] = fileName;
byte[] buffer = new byte[1000];
ZipOutputStream out =
new ZipOutputStream(new FileOutputStream(zipfilename));
out.setLevel(Deflater.DEFAULT_COMPRESSION);
for (int i = 0; i < filesToZipP.length; i++) {
FileInputStream in = new FileInputStream(filesToZipP[i]);
out.putNextEntry(new ZipEntry(filesToZipP[i]));
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
}
catch (IllegalArgumentException e) {
zipStatus = false;
}
return zipStatus;
}