java 解压文件的问题
zhuyc 2014-07-14 08:35:48 有一个内有一千个文件的压缩包,通过以下代码解压后只有43个文件!
public static boolean unRARFile(String rarFileName, String destDir) {
String unrarCmd = "C:\\Program Files (x86)\\WinRAR\\UnRar x ";
unrarCmd += rarFileName + " " + destDir;
try {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(unrarCmd);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
通过下面的代码,也是能解压出43个文件,但是线程一直在等待,但是强制停止后,所有文件就加压出来了,这是什么原因啊?
public static void main(String[] args) {
String rarFileName = "d:\\Users\\Desktop\\1\\ReadRQ.rar";
String destDir = "d:\\Users\\Desktop\\1\\";
String unrarCmd = "C:\\Program Files (x86)\\WinRAR\\UnRar x ";
unrarCmd += rarFileName + " " + destDir;
Runtime rt = null;;
Process p = null;
try {
rt = Runtime.getRuntime();
p = rt.exec(unrarCmd);
int exitVal = p.waitFor();
if (exitVal == 0) {
System.out.println("解压成功!");
}
} catch (Exception e) {
System.out.println(new Date() + ",解压失败:" + e.getMessage());
} finally {
p.destroy();
rt.freeMemory();
}
}