我有以下 WebDriver Java 代码用于将文件夹/目录压缩为 .zip :
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.io.Zip;
public class ZipDir {
public static void main(String... args){
Zip zip = new Zip();
try {
zip.zip(new File("D:\\TmpFS"), new File("D:\\TmpFS.zip"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
上面的代码成功在D盘创建了一个“TmpFS.zip”,不幸的是出现了如下异常:
java.util.zip.ZipException: ZIP file must have at least one entry
at java.util.zip.ZipOutputStream.finish(Unknown Source)
at java.util.zip.DeflaterOutputStream.close(Unknown Source)
at java.util.zip.ZipOutputStream.close(Unknown Source)
at com.google.common.io.Closeables.close(Closeables.java:77)
at org.openqa.selenium.io.Zip.zip(Zip.java:90)
at org.openqa.selenium.io.Zip.zip(Zip.java:51)
at packt.selenium.test.chapter6.ZipDir.main(ZipDir.java:11)
良好的帮助是可观的。