程序如下,可以运行压缩文件,就是有个问题,会出现winrar的“诊断信息”的提示:! 无法创建 d:\test.rar! 另一个程序正在使用此文件,进程无法访问。
这样的话接下去的其他程序就运行不了
public static boolean zip(String zipfile,String foler){
String rarPath="C:\\Program Files\\WinRAR\\WinRAR.exe";
String cmd=rarPath+" a " + zipfile +" "+ foler;
try{
Runtime.getRuntime().exec(cmd);
Process proc=Runtime.getRuntime().exec(cmd);
if(proc.waitFor() !=0){
if(proc.exitValue()==0)
return true;
}
}catch(Exception e){
e.printStackTrace();
}
return false;
}
这样的话接下去的其他程序就运行不了
public static boolean zip(String zipfile,String foler){
String rarPath="C:\\Program Files\\WinRAR\\WinRAR.exe";
String cmd=rarPath+" a " + zipfile +" "+ foler;
try{
Runtime.getRuntime().exec(cmd);
Process proc=Runtime.getRuntime().exec(cmd);
if(proc.waitFor() !=0){
if(proc.exitValue()==0)
return true;
}
}catch(Exception e){
e.printStackTrace();
}
return false;
}
先在进程里面杀掉再试
在dos窗口运行相同命令就没问题
这行去掉,多余了
String rarPath="C:\\Program Files\\WinRAR\\WinRAR.exe";
String cmd=rarPath+" a -inul " + zipfile +" "+ foler;