Could anyone post a simple snippet that does this?
Files are text files, so compression would be nice rather than just archive the files.
I have the filenames stored in an iterable.
Could anyone post a simple snippet that does this?
Files are text files, so compression would be nice rather than just archive the files.
I have the filenames stored in an iterable.
As suggested by Gabriele Petronella, in addition need to add below maven dependency in pom.xml as well and below imports
There's not currently any way to do this kind of thing from the standard Scala library, but it's pretty easy to use
java.util.zip
:I'm focusing on simplicity instead of efficiency here (no error checking and reading and writing one byte at a time isn't ideal), but it works, and can very easily be improved.
A bit modified (shorter) version using NIO2:
I recently had to work with zip files too and found this very nice utility: https://github.com/zeroturnaround/zt-zip
Here's an example of zipping all files inside a directory:
Very convenient.
The Travis answer is correct but I have tweaked a little to get a faster version of his code:
This is a little bit more scala style in case you like functional:
and don't forget the imports: