java调用winrar解压文件[rar.bz2.zip.....]
2012-02-03 14:23
381 查看
package com.czp; import java.io.File; import java.util.Properties; public class UnRarFile { public static void main(String[] args) { UnRarFile unrar = new UnRarFile(); unrar.unRarFileCurDir(new File("d:/ftpd/pm/test/*.bz2")); } /** * 解压文件 * * @param target * @param oldFile */ public void unRarFile(File target, File oldFile) { try { if (isWindow()) { String path = target.getParentFile().getAbsolutePath(); File tmp = target.getParentFile(); if (path.charAt(path.length() - 1) != ((char) File.separatorChar)) { tmp = new File(path + File.separator); if (!tmp.exists()) tmp.mkdirs(); } String cmd2 = "C:\\Program Files\\WinRAR\\winrar.exe x -r -o+ -ibck -y " + oldFile + " *.* " + tmp; Runtime rt = Runtime.getRuntime(); Process pre = rt.exec(cmd2); if (0 != pre.waitFor()) { pre.destroy(); } rt.runFinalization(); System.out.println(cmd2); } else { System.out.println("can't get rar command abort"); } } catch (Exception e) { System.out.println("解压发生异常"); } } /** * 解压到当前目录 * * @param filePath */ public void unRarFileCurDir(File filePath) { unRarFile(filePath, filePath); } /** * 是否是window * * @return */ public boolean isWindow() { Properties properties = System.getProperties(); String os = properties.getProperty("os.name"); if (os != null && os.contains("Windows")) return true; return false; } }
相关文章推荐
- SSIS基本应用--进程任务(调用WinRar解压文件)
- 调用WinRAR解压文件
- 【MFC】VC调用WinRar解压文件(如:.gz)
- Java 中调用 Apache API 实现图片文件的 压缩 与 解压 实例
- 利用VC调用WinRAR解压和压缩文件
- c# 调用 WinRAR 实现文件压缩、文件解压,WinRAR命令行参数,不弹窗
- 利用VC调用WinRAR解压和压缩文件
- c#调用WinRAR软件压缩和解压文件
- C++调用WinRAR压缩解压文件
- Java 调用 winrar 命令 批处理 压缩包文件
- JAVA利用cmd命令行调用WINRAR解压及压缩
- java学生管理系统(GUI)---第二个java文件(接上面的java程序,被调用的窗口)
- Java如何通过WSDL文件来调用这些web service
- java 文件解压
- 用java代码实现文件的zip压缩与解压
- java调用bat文件判断系统是32还是64位,并设置环境变量
- Java无需解压直接读取Zip文件和文件内容
- 详解Java无需解压直接读取Zip文件和文件内容
- java 将文件/目录下 zip压缩文件解压并删除压缩包
- 关于Java解压文件的一些坑及经验分享(MALFORMED异常)