Guest User

Untitled

a guest
Feb 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public static List<String> unzip(String zipFilePath) {
  2. try {
  3. File zipFile = new File(zipFilePath);
  4. try (ZipInputStream inputStream = new ZipInputStream(new FileInputStream(zipFile))) {
  5. List<String> fileList = new ArrayList<>();
  6. ZipEntry entry = inputStream.getNextEntry();
  7. while (entry != null) {
  8. File newFile = new File(zipFile.getParent() + File.separator + entry.getName());
  9. new File(newFile.getParent()).mkdirs();
  10. if (!entry.isDirectory()) {
  11. try (FileOutputStream outputStream = new FileOutputStream(newFile)) {
  12. int length;
  13. byte[] buffer = new byte[1024];
  14. while ((length = inputStream.read(buffer)) > 0) {
  15. outputStream.write(buffer, 0, length);
  16. }
  17. }
  18. }
  19. fileList.add(newFile.getAbsolutePath());
  20. entry = inputStream.getNextEntry();
  21. }
  22. inputStream.closeEntry();
  23. return fileList;
  24. }
  25. } catch (Exception e) {
  26. System.out.println(String.format("unzip error: %s", e));
  27. return Collections.emptyList();
  28. }
  29. }
Add Comment
Please, Sign In to add comment