Can anyone show me the correct way to compress and decompress tar.gzip files in java i've been searching but the most i can find is either zip or gzip(alone).
Tar and Gzip are two of the most common utilities for archiving and compressing files. More specificly, tar is used for archiving and gzip is used for compression, however the two are most often used in conjunction.
Create a FileOutputStream to the destination file, that is the file path to the output compressed file. Create a GZIPOutputStream to the above FileOutputStream . Create a FileInputStream to the file you want to compress. Read the bytes from the source file and compress them using GZIPOutputStream .
I've written a wrapper for commons-compress called jarchivelib that makes it easy to extract or compress from and into File
objects.
Example code would look like this:
File archive = new File("/home/thrau/archive.tar.gz"); File destination = new File("/home/thrau/archive/"); Archiver archiver = ArchiverFactory.createArchiver("tar", "gz"); archiver.extract(archive, destination);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With