Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. private boolean unpackZip(String path, String zipname){
  2. InputStream is;
  3. ZipInputStream zis;
  4. try
  5. {
  6. String filename;
  7. is = new FileInputStream(path + zipname);
  8. zis = new ZipInputStream(new BufferedInputStream(is));
  9. ZipEntry ze;
  10. byte[] buffer = new byte[1024];
  11. int count;
  12.  
  13. while ((ze = zis.getNextEntry()) != null)
  14. {
  15. // zapis do souboru
  16. filename = ze.getName();
  17.  
  18. // Need to create directories if not exists, or
  19. // it will generate an Exception...
  20. if (ze.isDirectory()) {
  21. File fmd = new File(path + filename);
  22. fmd.mkdirs();
  23. continue;
  24. }
  25.  
  26. FileOutputStream fout = new FileOutputStream(path + filename);
  27.  
  28. // cteni zipu a zapis
  29. while ((count = zis.read(buffer)) != -1)
  30. {
  31. fout.write(buffer, 0, count);
  32. }
  33.  
  34. fout.close();
  35. zis.closeEntry();
  36. }
  37.  
  38. zis.close();
  39. }
  40. catch(IOException e)
  41. {
  42. e.printStackTrace();
  43. return false;
  44. }
  45.  
  46. return true;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement