压缩包(zip、rar、rar5)解压
目前WinRAR最新使用的是rar5,rar5加密算法并未开源。网上unrar也只能rar4进行解压;
因此通过安装winrar软件,CMD方式调用软件进行解压是一个无奈的选择;
Windows服务器调用winrar
CMD使用winrar详解
Winrar的命令行模式程序在安装目录下的 rar.exe (打包压缩程序),unrar.exe(解压缩程序),Rar.txt(帮助文档)
RAR常用命令示例
//解压压缩文件
"rar X " + compressFile + " " + destDir;
//解压并覆盖解压文件
"rar X -o+ " + compressFile + " " + destDir;
//解压带密码的压缩文件
"rar X -p"+pwd+" "+ compressFile + " "+destDir;
//解压带密码的压缩文件并覆盖解压文件
"rar X -o+ -p"+pwd+" "+ compressFile + " "+destDir;
//解压带密码的压缩文件并覆盖解压文件
"rar X -o+ -p"+pwd+" "+ compressFile + " "+destDir;
//列出压缩文件信息
"rar l -v "+compressFile
解压示例
// 开始调用命令行解压,参数-o+是表示覆盖的意思//winrar软件路径String winrarPath = "D:/winrar/WinRAR.exe"//压缩文件路径String compressFile = "D:/test.rar"//解压目录String destDir = "D:/test";//密码//String pwd = "123456"; String cmd = winrarPath + " X -o+ " + compressFile + " " + destDir;//String cmd = "cmd.exe /c "+winrarPath + " X -o+ -p"+pwd+" "+ compressFile + " "+destDir; System.out.println(cmd);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();}System.out.println("解压" + (bool ? "成功" : "失败"));
Linux服务器调用winrar
安装linux版rar
1.下载RAR官网下载地址:https://www.rarlab.com/download.htmwget下载:wget http://www.rarsoft.com/rar/rarlinux-x64-5.6.1.tar.gz
2.安装:tar -zxf rarlinux-x64-5.0.1.tar.gzcd rarmake && make install
3.解压/压缩解压:rar x ***.rar 压缩:rar a ***.rar /***