public class Unrar {public static final String winrarPath = "C://Program Files//WinRAR//WinRAR.exe"; public static boolean unrar(String rarFile, String target) { boolean bool = false; File f=new File(rarFile); if(!f.exists()){ return false; } String cmd = winrarPath + " X " + zipFile + " "+target; try { Process proc = Runtime.getRuntime().exec(cmd); if (proc.waitFor() != 0) { if (proc.exitValue() == 0) { bool = false; } } else { bool = true; } } catch (Exception e) { e.printStackTrace(); } return bool; }private static void unzip(String sourceZip,String destDir) throws Exception{ try{ Project p = new Project(); Expand e = new Expand(); e.setProject(p); e.setSrc(new File(sourceZip)); e.setOverwrite(false); e.setDest(new File(destDir)); e.setEncoding("gbk"); e.execute(); }catch(Exception e){ throw e; } }public static void main(String[] args) { String rarFile= "D://a.rar"; String zipFile= "D://a.zip"; String rartarget= "D://123//";String ziptarget= "D://456//";unzip(zipFile, ziptarget);boolean b = unrar(rarFile, rartarget); System.out.println(b); }
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!