How do I extract a tar (or tar.gz, or tar.bz2) file in Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note: This functionality was later published through a separate project, Apache Commons Compress, as described in another answer. This answer is out of date.
I haven’t used a tar API directly, but tar and bzip2 are implemented in Ant; you could borrow their implementation, or possibly use Ant to do what you need.
Gzip is part of Java SE (and I’m guessing the Ant implementation follows the same model).
GZIPInputStreamis just anInputStreamdecorator. You can wrap, for example, aFileInputStreamin aGZIPInputStreamand use it in the same way you’d use anyInputStream:(Note that the GZIPInputStream has its own, internal buffer, so wrapping the
FileInputStreamin aBufferedInputStreamwould probably decrease performance.)