我有用於壓縮文件夾/目錄的.zip下面的webdriver Java代碼:在d驅動壓縮/壓縮使用硒的webdriver與Java
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();
}
}
}
上面的代碼創建一個「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)
很好的幫助是很大的。
嘗試創建zip文件時,目錄「D:\\ TmpFS」中是否存在任何文件? – SrikanthLingala
D上沒有現有文件:\\ TmpFS –