读取zip
try{ 
      ZipFile myZipFile; 
      Enumeration myZipFileEnum;
 
      myZipFile = new java.util.zip.ZipFile("c:\\livetri.zip"); 
      myZipFileEnum = myZipFile.entries(); 
      while(myZipFileEnum.hasMoreElements()){ 
          out.println(myZipFileEnum.nextElement().toString());
          out.println(""); 
      } 
}catch(ZipException e){
 
}

解决方案 »

  1.   

    刚好今天学着写了一个很简单的程序,大概是那么个意思
    public class FileReadTest {
        protected String zipFilePath = "e:\\test.zip";
        protected String DisName = "e:\\test\\";
        protected String INZIP = "e:\\test";
        protected String DisFileName = null;
        
        byte[] bytes = new byte[1024];
        int i = -1;
        int index;
        ZipEntry zipEntry;    
        
        public void ZipReadTest() throws IOException, DataFormatException{
            System.out.println("ZipReadTest---------------------Start");        FileInputStream fileInputStream;
            FileOutputStream fileOutputStream = null;
            
            fileInputStream = new FileInputStream(zipFilePath);
            BufferedInputStream bufferedInputStream = new BufferedInputStream( fileInputStream );
            ZipInputStream zipInputStream = new ZipInputStream( bufferedInputStream);
            
            //get the entry of the zip 
            while( (zipEntry = zipInputStream.getNextEntry()) != null){
                String entryName = zipEntry.getName();
                DisFileName = entryName;
               
                if(entryName.endsWith(".java")){
                    //get the name of file whose suffix is ".java",and then named output file with it                
                    if((index = entryName.indexOf("/")) != -1){
                        DisFileName = DisFileName.substring( index + 1 );
                    }
                    
                    System.out.println("--------------" + DisFileName);
                    //output the file whose suffix is ".java"
                 fileOutputStream = new FileOutputStream(DisName + DisFileName);
                    while(( i = zipInputStream.read(bytes)) != -1){
                        fileOutputStream.write(bytes,0,i);
             fileOutputStream.flush();
                    }
                }
                zipInputStream.closeEntry();
            }        zipInputStream.close();
            fileOutputStream.close();
            bufferedInputStream.close();
        }
        
        public static void main(String[] args) throws IOException, DataFormatException {
            FileReadTest fileReadTest = new FileReadTest();
            fileReadTest.ZipReadTest();
        }
    }
      

  2.   

    如果是xp那么直接用
    Runtime.exec调用zip32就可以了。
      

  3.   

    你的这个方法还必须手动创建文件夹
    可以这样File aa=new File(INZIP);
            aa.mkdir();