用JAVA解决调用ZIP的若干个事
记录下最近解决ZIP的思路
1.如何处理压缩解压ZIP中密码问题
JDK自带ZIP库和常用的ANT中带的ZIP库没有解决密码问题,期初希望找到开源有提供这样的库,因为了解到.NET中有提供个SharpZipLib库可以解决,但话了一段时间没找到,最后觉得直接用WINRAR解决算了,虽然部署要安装比较麻烦,但winrar提供的功能多能解决。如下例子:
//解压
String pw="123";
String cmd="d:\\Program Files\\WinRAR\\winrar X -p" + pw +" \\\\192.168.1.22\\FTPServer\\webmail\\xx.zip f:\\xx";
try{
Runtime.getRuntime().exec(cmd);
}catch(Exception ex){
ex.printStackTrace();
}
2.用WINRAR解决ZIP的添加,删除
//压缩
String pw="123";
String cmd="d:\\Program Files\\WinRAR\\winrar a -ep -p" + pw +" f:\\xx\\xx.zip F:\\xx\\aa.jpg F:\\xx\\aa.html ";
try{
Runtime.getRuntime().exec(cmd);
}catch(Exception ex){
ex.printStackTrace();
}
//追加压缩
String pw="123";
String cmd="d:\\Program Files\\WinRAR\\winrar a -ep -p" + pw +" F:\\xx\\aa.zip F:\\xx\\add.html ";
try{
Runtime.getRuntime().exec(cmd);
}catch(Exception ex){
ex.printStackTrace();
}
//删除压缩
String pw="123";
String cmd="d:\\Program Files\\WinRAR\\winrar d -p" + pw +" F:\\xx\\xx.zip aa.html";
try{
Runtime.getRuntime().exec(cmd);
}catch(Exception ex){
ex.printStackTrace();
}