Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. public void unzip() throws IOException {
  2.         ArrayList<String> listOfArchives = getListOfFiles();
  3.  
  4.         for (String s : listOfArchives) {
  5.             String filename = path + "/" + s;
  6.             File file = new File(filename);
  7.             if (!file.exists() || !file.canRead()) {
  8.                 System.out.println("File cannot be read");
  9.                 return;
  10.             }
  11.  
  12.  
  13.             ZipFile zip = new ZipFile(filename);
  14.             try {
  15.                 Enumeration entries = zip.entries();
  16.  
  17.                 while (entries.hasMoreElements()) {
  18.                     ZipEntry entry = (ZipEntry) entries.nextElement();
  19.  
  20.                     if (!entry.isDirectory() && entry.getName().matches(regExpression)) {
  21.                         try (BufferedOutputStream bf = new BufferedOutputStream(new FileOutputStream(new File(file.getParent(), entry.getName())))) {
  22.                             write(zip.getInputStream(entry), bf);
  23.                         }
  24.                     }
  25.                 }
  26.  
  27.                 zip.close();
  28.  
  29.             } catch (IOException e) {
  30.                 e.printStackTrace();
  31.             }
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement