Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<String> unzip(String zipFilePath) {
- try {
- File zipFile = new File(zipFilePath);
- try (ZipInputStream inputStream = new ZipInputStream(new FileInputStream(zipFile))) {
- List<String> fileList = new ArrayList<>();
- ZipEntry entry = inputStream.getNextEntry();
- while (entry != null) {
- File newFile = new File(zipFile.getParent() + File.separator + entry.getName());
- new File(newFile.getParent()).mkdirs();
- if (!entry.isDirectory()) {
- try (FileOutputStream outputStream = new FileOutputStream(newFile)) {
- int length;
- byte[] buffer = new byte[1024];
- while ((length = inputStream.read(buffer)) > 0) {
- outputStream.write(buffer, 0, length);
- }
- }
- }
- fileList.add(newFile.getAbsolutePath());
- entry = inputStream.getNextEntry();
- }
- inputStream.closeEntry();
- return fileList;
- }
- } catch (Exception e) {
- System.out.println(String.format("unzip error: %s", e));
- return Collections.emptyList();
- }
- }
Add Comment
Please, Sign In to add comment