I have BodyPart object from email which is a .zip archive. And i need to extract all files from it, but can't find any solution. I tried this:

List<File> files = new ArrayList<>();
        try (ZipInputStream zis = (ZipInputStream)bodyPart.getInputStream()) {
            ZipEntry zipEntry;
            while ((zipEntry = zis.getNextEntry()) != null) {
                LOG.info("Unzipping: {}", zipEntry.getName());
                File file = new File(zipEntry.getName());
        return files;

But it throws exception on casting bodyPart.getInputStream to ZipInputStream'.

Is there another way to convert .zip BodyPart to list of archive's content?

0 Answers