你要是解压zip文件的话还好说,java中有对zip文件的支持
rar,你就要看看有没有相关控件了
或者你找一些rar的资料,自己搞一个

解决方案 »

  1.   

    这是大部分代码。你看看就明白FileInputStream fis=new FileInputStream(jarFileName);BufferedInputStream bis=new BufferedInputStream(fis);ZipInputStream zis=new ZipInputStream(bis);ZipEntry ze=null;while ((ze=zis.getNextEntry())!=null) {if (ze.isDirectory()) {continue;}if (debugOn) {System.out.println("ze.getName()="+ze.getName()+","+"getSize()="+ze.getSize());}int size=(int)ze.getSize();// -1 表示大小未知。if (size==-1) {size=((Integer)htSizes.get(ze.getName())).intValue();}byte[] b=new byte[(int)size];int rb=0;int chunk=0;while (((int)size - rb) > 0) {chunk=zis.read(b,rb,(int)size - rb);if (chunk==-1) {break;}rb+=chunk;}
      

  2.   

    /**
     * <p>Title: 解压文件处理 </p>
     * <p>Description: 实现与解压文件的相关的处理 </p>
     * <p>Copyright: Copyright (c) 2003-2010</p>
     * @version 1.0 03/08/12
     */import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    import sun.io.*;public class Zip {
      public String errMsg = "";  public Zip() {
      }  /**
       * 解压文件
       * @param filePath 文件路径
       * @param fileName 文件名称
       * @return 错误信息字符串
       */
      public String execute(String filePath, String fileName) {
        File infile = new File(filePath + fileName);
        try {
          //检查是否是一个zip文件
          ZipFile zip = new ZipFile(infile);
          zip.close();
          //建立与目标文件的输入连接
          ZipInputStream in = new ZipInputStream(new FileInputStream(infile));
          ZipEntry file = in.getNextEntry();
          int i = infile.getAbsolutePath().lastIndexOf(".");
          String dirname = new String();
          if (i != -1) {
            dirname = infile.getAbsolutePath().substring(0, i);
          } else {
            dirname = infile.getAbsolutePath();
          }
          ///JOptionPane.showMessageDialog(null, "1. " + dirname, "显示", JOptionPane.CLOSED_OPTION);
          File newdir = new File(dirname);
          newdir.mkdir();//创建第一级目录      byte[] c = new byte[1024];
          int len;
          int slen;      while (file != null) {
            i = file.getName().replace('/', '\\').lastIndexOf('\\');
            if (i != -1) {
              File dirs = new File(dirname + File.separator + file.getName().replace('/', '\\'));
              dirs.mkdir();
              dirs = null;
              ///JOptionPane.showMessageDialog(null, "2. " + String.valueOf(i) + dirname + File.separator + file.getName().replace('/', '\\').toString(), "显示", JOptionPane.CLOSED_OPTION);
              //System.exit(0);
             }        if (file.isDirectory()) {
              File dirs = new File(dirname + File.separator + file.getName().replace('/', '\\'));
              dirs.mkdir();
              dirs = null;
              ///JOptionPane.showMessageDialog(null, "3. " + dirname + File.separator + file.getName().replace('/', '\\').toString(), "显示", JOptionPane.CLOSED_OPTION);
            } else {
              FileOutputStream out = new FileOutputStream(dirname  + File.separator + file.getName().replace('/', '\\'));
              while ((slen = in.read(c, 0, c.length)) != -1) {
                out.write(c, 0, slen);
              }
                out.close();
            }        file = in.getNextEntry();      }
          errMsg = infile.getName() + "解压成功!";
          in.close();
          return errMsg;    } catch (ZipException zipEx) {
          errMsg = infile.getName() + "不是一个zip文件!";
          return errMsg;
        } catch (IOException ioEx) {
          errMsg = "读取" + infile.getName() + "文件时出错!";
          return errMsg;
        } catch (Exception Ex) {
          errMsg = infile.getName() + "文件不存在!";
          return errMsg;
        }
      }
    }http://xieweibbs.topcities.com
      

  3.   

    各位老大,你们给的都是ZIP的例子啊,我需要的是RAR的例子啊