1.可以自己写一个java解压文件的程序
2.如果一定要调用bat文件的话可以这样
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd /c dir");
类似这样

解决方案 »

  1.   

    有没有简单一些,把命令写在bat文件里面调用bat命令就可以解压WinRAR文件或zip文件的方式
      

  2.   

    winrar 的路径没有进系统的环境变量 直接给出winrar的全路径 或者先切换到rar程序的路径里
      

  3.   

    java-unrar.jar 这个库可以支持解压rar文件,至于zip的java本身就支持的。import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;import de.innosystec.unrar.Archive;
    import de.innosystec.unrar.rarfile.FileHeader;public class RarFileUtil {

    public static boolean existZH(String str) {
    String regEx = "[\\u4e00-\\u9fa5]";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    return m.find();
    } public static String getFileName(String fileName) {
    if (null == fileName && "".equals(fileName)) {
    return "";
    }
    int index = fileName.lastIndexOf(".");
    return fileName.substring(0, index);
    } public static boolean unrarFile(String rarFilePath, String extPlace) {
    boolean flag = false;
    if (null == rarFilePath || "".equals(rarFilePath.trim())) {
    System.out.println("rar文件路径为空.");
    return flag;
    } else {
    int index = rarFilePath.lastIndexOf(".");
    if (index > -1) {
    String suffix = rarFilePath.substring(index + 1,
    rarFilePath.length());
    if (!"rar".equalsIgnoreCase(suffix)) {
    System.out.println("压缩文件格式不正确.");
    return flag;
    }
    }
    }
    if (null == extPlace || "".equals(extPlace.trim())) {
    System.out.println("解压路径为空.");
    return flag;
    } Archive archive = null;
    OutputStream os = null; try {
    File file = new File(rarFilePath);
    String extDir = extPlace + getFileName(file.getName())
    + File.separator;
    archive = new Archive(file);
    FileHeader fh = archive.nextFileHeader(); String fileName = null;
    String path = null;
    String dirPath = null;
    File dir = null;
    while (null != fh) {
    fileName = fh.getFileNameW().trim();
    if (!existZH(fileName)) {
    fileName = fh.getFileNameString();
    } path = (extDir + fileName).replaceAll("\\\\", "/");
    int end = path.lastIndexOf("/");
    if (end > -1) {
    dirPath = path.substring(0, end);
    } dir = new File(dirPath);
    if (!dir.exists()) {
    dir.mkdirs();
    } if (fh.isDirectory()) {
    fh = archive.nextFileHeader();
    continue;
    } os = new FileOutputStream(extDir + fileName);
    archive.extractFile(fh, os);
    os.flush();
    os.close(); fh = archive.nextFileHeader();
    }
    flag = true;
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if (null != os) {
    try {
    os.flush();
    os.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    if (null != archive) {
    try {
    archive.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    } return flag;
    }

    public static void main(String[] args){
    unrarFile("E:\\新建文件夹.rar","E:\\");

    }
    }
    简单的例子,不过例子有点问题,仅供参考
      

  4.   

    这个问题的本质就是楼主你没有安装WinRAR,或者安装了但是没有把WinRAR的路径写到环境变量里。
    解决方法:
    安装WinRAR,把安装路径写到环境变量里。在dos里输入WinRAR命令可以查看是否生效。楼上的叫人家用这个库那个工具的,都不认真看问题就回答的吗?
      

  5.   

    winRar命令解压没用过,我只用过7Z解压。飘过。
      

  6.   

    试下这个看行不行?public static void open(){
            
            if (java.awt.Desktop.isDesktopSupported()) {
                try {
                    java.awt.Desktop dp = java.awt.Desktop.getDesktop();
                    if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
                        dp.open(new File("D:\\xxx.bat"));//把应用程序的地址传进来即中打开
                        
                    }
                } catch (java.lang.NullPointerException e) {
                    
                } catch (java.io.IOException e) {
                    
                }
            }
        }
      

  7.   

    @echo off
    "C:\Program Files\WinRAR\WinRAR.exe" e -y -inul "一键搞定.rar"