使用java提取zip文件的最佳方法是什么

使用java提取zip文件的最佳方法是什么,java,compression,Java,Compression,我有一个压缩文件。该文件还包含各种目录和文件。我想提取所有这些并保存在指定的路径中 因此,如何编写java程序来提取压缩文件 谢谢 Sunil Kumar Sahoo您应该研究如何使用。Sun提供了一个关于如何使用它的教程:。您应该研究如何使用。Sun提供了一个关于如何使用它的教程:.java.util.zip.*完成所需的操作。 检查API以获取参考。例如,如果您正在查找java.util.zip.*执行所需的操作。 检查API以获取参考。例如,如果您正在查找的是的可能副本 public st

我有一个压缩文件。该文件还包含各种目录和文件。我想提取所有这些并保存在指定的路径中

因此,如何编写java程序来提取压缩文件

谢谢
Sunil Kumar Sahoo

您应该研究如何使用。Sun提供了一个关于如何使用它的教程:。

您应该研究如何使用。Sun提供了一个关于如何使用它的教程:.

java.util.zip.*完成所需的操作。
检查API以获取参考。例如,如果您正在查找java.util.zip.*执行所需的操作。 检查API以获取参考。例如,如果您正在查找的是

的可能副本
public static  void unzip(){
      try{
           BufferedOutputStream out = null;
           ZipInputStream  in = new ZipInputStream(ZipFileExtracter.class.getClassLoader().getResourceAsStream("com/artificialmachines/chitme/stamps/ChitMeData.zip"));
           ZipEntry entry;
           boolean isDirectory=false;
           while((entry = in.getNextEntry()) != null){
               int count;
               byte data[] = new byte[BUFFER];
               // write the files to the disk
               String entryName = entry.getName();
               File newFile = new File(new StringBuffer().append(System.getProperty("user.dir")).append(File.separator).append(entryName).toString());
               if(entryName.endsWith("/")){
                   isDirectory=true;
                   newFile.mkdir();
                   //System.out.println("This is directory "+newFile.exists()+"  IS DIr "+newFile.isDirectory()+"    path "+newFile.getPath());
               }else{
                   newFile.createNewFile();
               }
               if(!isDirectory){
                   out = new BufferedOutputStream(new FileOutputStream(newFile),BUFFER);
                    while ((count = in.read(data,0,BUFFER)) != -1){
                         out.write(data,0,count);
                    }
                    cleanUp(out);
               }
               isDirectory=false;
           }
           cleanUp(in);
      }
      catch(Exception e){
           e.printStackTrace();
           System.exit(0);
      }
   }