本帖最后由 zft1518912563 于 2012-06-24 16:33:47 编辑

解决方案 »

  1.   

    那你得先知道那个压缩文件的解压算法。或者那个解压文件有支持java的库
      

  2.   

    public static void testZipToUnzip(ZipFile zipfile,File file){
      //将一个压缩文件zipfile(可以包含文件)解压到file文件中
      ZipEntry ze=null;
      File outfile;
      InputStream zis=null;
      FileOutputStream fos=null;
      Enumeration e=zipfile.getEntries();
      while(e.hasMoreElements()){
       ze=(ZipEntry) e.nextElement();
          // System.out.println(ze.getName());
       outfile=new File(file+File.separator+ze.getName());   
       //if(ze.toString().length()!=(ze.getName()).lastIndexOf('/')+1)
       //这句话的作用:如果ze不是一个目录则执行下面的语句,也就是创建输出文件并且将输入流输出到输出流中。
       //上面的if语句作用和该语句作用一样
       if(!ze.isDirectory()){         
        try {
         //System.out.println(ze.getName());
         zis=zipfile.getInputStream(ze);
         //System.out.println(ze.getSize());    
         //System.out.println(outfile.getPath());     
         if(!outfile.exists())
          //如果输出文件不存在,那么创建输出文件的父目录
          outfile.getParentFile().mkdirs();    
     fos=new FileOutputStream(outfile);     
         byte[] b=new byte[1024];
         int len;
         while((len=zis.read(b))>0){
          fos.write(b, 0, len);
         }
         fos.close();
         zis.close();
        } catch (ZipException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
        } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
        }
       }
    }
    这是我写的解压代码,运行通过,如果有问题,可以发邮件至[email protected],希望能帮助你。
      

  3.   

    不解压怎么读取啊?你不要以为你使用 WinRAR 打开这个压缩文件,双击某个文件就能打开了。WinRAR 在你不知道的情况下解压到了临时目录中,这样你才有可能打开!