Quantcast
Channel: Mendix Forum Questions
Viewing all articles
Browse latest Browse all 82391

Unzip an file and store the files and folders to disk

$
0
0

Hello, I would like to unzip a file, which I import in the application. I want to unzip the file and store the files and folders to the disk. How do I create a java action for the same? Kindly advice. Thanks in advance.

byte[] buffer = new byte[1024];
    ZipInputStream zis = new ZipInputStream(Core.getFileDocumentContent(getContext(), __ParameterParameter1));
    File folder = new File("C:\\outputzip1");
    OutputStream outstream = new FileOutputStream(folder);
    ZipEntry ze = zis.getNextEntry();
    while(ze != null){
        String filename = ze.getName();
        File newFile = new File(outstream + File.separator + filename);
        new File(newFile.getParent()).mkdirs();
        OutputStream outstream1 = new FileOutputStream(newFile);
        int len;
        while ((len = zis.read(buffer)) > 0) {
            outstream1.write(buffer, 0, len);
            }
        outstream1.close();
        ze = zis.getNextEntry();
    }

--Edit: shows, "java.security.AccessControlException: access denied ("java.io.FilePermission""C:\outputzip1""write")" error when executed. What exactly should I do? Thanks.


Viewing all articles
Browse latest Browse all 82391

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>