Noél Dubau Posted November 21, 2019 Posted November 21, 2019 (edited) Hello In the SM sample file exists an Unzip module requiring to choose the zip file ; the file is expanded in a folder named as the original file Has someone adapted this module in the idea of unzipFile(filesource ; folderDestination) Thanks for links Noël Edited November 21, 2019 by Noél Dubau
ericire Posted November 22, 2019 Posted November 22, 2019 hello dear Noël 😊 yes, easy with two parameters sourcePath and destPath : Quote import java.util.zip.*; import java.io.*; import java.util.*; if(sourcePath == null || sourcePath.equals("") || destPath == null || destPath.equals("")) { return 'Les paramètres sourcePath et destPath doivent être renseignés' } /* * Create directory with the name of the zip file * * For e.g. if we are going to extract c:/demo.zip create c:/demo * directory where we can extract all the zip entries * */ try { File fSourceZip = new File(sourcePath); String zipPath = destPath File temp = new File(zipPath); temp.mkdir(); /* * Extract entries while creating required * sub-directories * */ ZipFile zipFile = new ZipFile(fSourceZip); Enumeration e = zipFile.entries(); while(e.hasMoreElements()) { ZipEntry entry = (ZipEntry)e.nextElement(); File destinationFilePath = new File(zipPath,entry.getName()); //create directories if required. destinationFilePath.getParentFile().mkdirs(); //if the entry is directory, leave it. Otherwise extract it. if(entry.isDirectory()) { continue; } else { System.out.println("Extracting " + destinationFilePath); /* * Get the InputStream for current entry * of the zip file using * * InputStream getInputStream(Entry entry) method. */ BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); int b; byte[] buffer = new byte[1024]; /* * read the current entry from the zip file, extract it * and write the extracted file. */ FileOutputStream fos = new FileOutputStream(destinationFilePath); BufferedOutputStream bos = new BufferedOutputStream(fos,1024); while ((b = bis.read(buffer, 0, 1024)) != -1) { bos.write(buffer, 0, b); } //flush the output stream and close it. bos.flush(); bos.close(); //close the input stream. bis.close(); } } zipFile.close(); } catch(IOException ioe) { return "IOError :" + ioe; } return 1;
Noél Dubau Posted November 22, 2019 Author Posted November 22, 2019 Thanks a lot my dear Eric ! I'll try it to morrow and I'm sur you'lll be one more time my savior ! have a good night ! Noël PS : As you see I've a ot of problems with other modules ; I've saved my disk, reinstalled all apps ands extesions... but errors are still present ! Grrrr
Recommended Posts
This topic is 1838 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now