java调用7zip demo

来源:互联网 发布:只有程序员才懂的笑话 编辑:程序博客网 时间:2024/06/10 08:39
import java.io.IOException;




public class ZIPTest2 {

public static void main(String[] args) throws Exception {
//
String tool = "C:\\Program Files\\7-Zip\\7z.exe";
String sourcefolder = "E:\\test\\*";
String targetZip = "E:\\test.zip";


String exec = String.format("%s a \"%s\" \"%s\"", tool, targetZip, sourcefolder);
Runtime runtime = Runtime.getRuntime();
Process pro  = runtime.exec(exec);
int result = pro.waitFor();
if(result != 0){
System.out.println("init zip error.");
}
pro.destroy();
 
Thread.sleep(1000);
 
String addfile = String.format("%s a \"%s\" -aoa \"%s\"", tool, targetZip, "E:\\test2");
pro = runtime.exec(addfile);
result = pro.waitFor();
if(result != 0){
System.out.println("update file .iso error.");
}
pro.destroy();
 
 
runtime.freeMemory();
runtime.gc();
}


}
0 0
原创粉丝点击