I want to share with you a simple solution for zipping files using Java capabilities.
On the bottom of this post you may find an nsf-file that contains one Java library - ZipFile.
'ZipFile' Java library contains one class ZipFile with a single method zipMyFile:
zipMyFile(String filesToZip, String zipFilePath, String compressionLevel, boolean withFolderTree)
Honestly speaking, I did not write it from the scratch.
I found some examples in Internet and reworked them into this solution.
Method zipMyFile works with 4 parameters:
- a list of files you want to zip joined via '|', every file should contain an absolute path.
- an absolute path for output zip-file
- compression level: BEST_COMPRESSION, BEST_SPEED, DEFAULT_COMPRESSION, DEFAULT_STRATEGY, DEFLATED, FILTERED, HUFFMAN_ONLY, NO_COMPRESSION
- boolean flag that defines if zipping files should save their folders tree inside of output zip-file. If you set this flag to 0, then all files will be zipped to the root of zip-file.
Except this Java class, database contains form 'ZipFile' for testing purposes.
Note: this solution does not check a case when user selects a few files from different folders but with the same name and parameter withFolderTree = 0. In this case user gets an error since it is impossible to have a few files with the same name in the root of zip-file.
ypastov.zipping.nsf
No comments:
Post a Comment