Guest User

Untitled

a guest
Jan 4th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public static void createFile(File file) throws IOException {
  2. if (file.exists()) {
  3. return;
  4. }
  5. File parentFile = file.getParentFile();
  6. if (!parentFile.exists())
  7. parentFile.mkdirs();
  8. file.createNewFile();
  9. }
  10.  
  11. public static void unzip(File archive, File output) throws IOException {
  12. byte[] buffer = new byte[1500];
  13. if (!output.exists()) {
  14. output.mkdir();
  15. }
  16. ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(archive)));
  17. ZipEntry ze;
  18. while ((ze = zis.getNextEntry()) != null) {
  19. File newFile = new File(output, ze.getName());
  20. if (!ze.isDirectory()) {
  21. createFile(newFile);
  22. BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(newFile));
  23. int len;
  24. while ((len = zis.read(buffer)) > 0)
  25. fos.write(buffer, 0, len);
  26. fos.close();
  27. }
  28. }
  29. zis.close();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment