content: package com.antfortune.freeline.util;
  
  import java.io.BufferedInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipInputStream;
  
  /**
   * Created by huangyong on 16/7/30.
   */
  public class FileUtils {
  
      public static void rm(File f) {
          if (f.isDirectory()) {
              for (File ff : f.listFiles()) {
                  rm(ff);
              }
              f.delete();
          } else if (f.isFile()) {
              f.delete();
          }
      }
  
      public static void unzip(File zipFile, File targetDirectory) throws IOException {
          ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
          try {
              ZipEntry ze;
              int count;
              byte[] buffer = new byte[8192];
              while ((ze = zis.getNextEntry()) != null) {
                  File file = new File(targetDirectory, ze.getName());
                  File dir = ze.isDirectory() ? file : file.getParentFile();
                  if (!dir.isDirectory() && !dir.mkdirs())
                      throw new FileNotFoundException("Failed to ensure directory: " + dir.getAbsolutePath());
                  if (ze.isDirectory())
                      continue;
                  FileOutputStream fout = new FileOutputStream(file);
                  try {
                      while ((count = zis.read(buffer)) != -1)
                          fout.write(buffer, 0, count);
                  } finally {
                      fout.close();
                  }
              }
          } finally {
              zis.close();
          }
      }
  
  }
  