Convert ZIP to TAR.GZ in Java Programmatically

TAR.GZ and ZIP are heavily used for archiving and compression of files/directories. Both file formats work well on almost all popular operating systems. However, TAR.GZ provides enhanced performance when it comes to compressing larger directories along with other metadata. So, in this blog post, we will learn how to programmatically convert ZIP to TAR.GZ in Java. For that sake, we will opt for Aspose.ZIP for Java which is a highly dependable API to create a TAR.GZ file. Further, you can automate the whole process by developing a ZIP to TAR.GZ converter for your business software.

The following points will be covered:

  1. Java API For TAR Archive - Installation
  2. Convert ZIP to TAR.GZ in Java Programmatically
  3. ZIP to TAR.GZ Converter - Online Tool

Java API For TAR Archive - Installation

We will install this library to implement the functionality. So, you have two options, first, you can download the JAR file or second, you can follow the Maven configurations given below:

 <repositories>
     <repository>
         <id>snapshots</id>
         <name>repo</name>
         <url>http://repository.aspose.com/repo/</url>
     </repository>
</repositories>
 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-zip</artifactId>
        <version>24.5</version>
    </dependency>
</dependencies>
java tar api

Convert ZIP to TAR.GZ in Java Programmatically

One thing to notice here, is that you have the source ZIP file to implement the ZIP to TAR.GZ conversion.

The following steps demonstrate how to generate TAR.GZ file using Aspose.ZIP for Java:

  • Create an instance of the Archive class and load the source ZIP file.
  • Instantiate an object of the TarArchive class.
  • Get the entries of RarArchiveEntry type constituting the RAR archive by calling the getEntries method.
  • Invoke the createEntry method to create a single entry within the archive.
  • Save as the TAR.GZ archive by calling the saveGzipped method.

Copy & paste the following code sample into your server file and run the server to convert ZIP to TAR.GZ in Java:

You can see the output in the image below:

ZIP to TAR.GZ Converter

ZIP to TAR.GZ Converter - Online Tool

Now, this section introduces an online tool powered by Aspose.ZIP for Java. In fact, this ZIP to TAR.GZ converter enables you to convert ZIP files to other popular file formats online. In addition, it is web-based and offers robust conversion features. Above all, there is no fee attached to its usage and you can perform your conversion easily.

ZIP to TAR.GZ Converter

Create a TAR.GZ File - Get a Free License

You can get a free temporary license to try this Java API without evaluation limitations.

Summing up

To conclude, Aspose.ZIP for Java not only offers conversion features but also provides programmatic creation and manipulation of archive formats. So, this guide demonstrated how to convert ZIP to TAR.GZ in Java along with steps and a code snippet. Therefore, you can visit the documentation, and API references to learn more.

You can see this Getting Started guide to start development. Finally, aspose.com will publish other useful blog posts, so stay connected.

Ask a question

You can let us know about your questions or queries on our forum.

Frequently Asked Questions – FAQs

How to turn ZIP into TAR.GZ?

Aspose.ZIP provides robust solutions in multiple programming languages to achieve ZIP to TAR.GZ conversion. So, for Java, please visit this link.

See Also