Beispiel #1
0
 private boolean deleteDirectory(File path) {
   File[] files = path.listFiles();
   for (int i = 0; i < files.length; i++) {
     File f = files[i];
     if (f.isFile()) {
       if (!f.delete()) {
         return false;
       }
     } else {
       if (!deleteDirectory(f)) {
         return false;
       }
     }
   }
   if (path.delete()) {
     return true;
   } else {
     return false;
   }
 }
Beispiel #2
0
  private boolean saveAndVerify(ZipInputStream data) throws IOException {
    try {
      ZipEntry ze;
      while ((ze = data.getNextEntry()) != null) {
        // Filename + reference to file.
        String filename = ze.getName();
        File output = new File(local_path + filename);

        if (filename.endsWith("/")) {
          output.mkdirs();
        } else {
          if (output.exists()) {
            // Delete the file if it already exists.
            if (!output.delete()) {
              return false;
            }
          }
          if (output.createNewFile()) {
            FileOutputStream out = new FileOutputStream(output);
            byte[] buffer = new byte[1024];
            int count;
            while ((count = data.read(buffer)) != -1) {
              out.write(buffer, 0, count);
            }
          } else {
            return false;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    } finally {
      data.close();
    }
    return true;
  }