Overwiew

Sometimes we need to combine files for better handling, without necessarily compressing them. When dealing with already compressed formats like JPEG or DOCX, further compression offers minimal space savings. Archiving uncompressed files is also beneficial when quick access to individual files is essential, as compressed archives require decompression first. In scenarios with limited computational resources, opting for uncompressed archives can reduce processing overhead, ensuring faster archival and extraction processes without the burden of compression algorithms.
Aspose.ZIP supports several archive formats for storing your data. Here's how to create such archives.

How to Store Files in Uncompressed ZIP Archives Using Java

When dealing with scenarios where file size isn’t a major concern, Java allows you to efficiently store files within ZIP archives without applying compression. This is particularly beneficial for situations where maintaining the original file structure and ensuring quick access to individual files is crucial. For store files within ZIP archive, use StoreCompressionSetting while initializing Archive instance.
Here’s how to achieve uncompressed storage in Java:

    try (FileOutputStream zipFile = new FileOutputStream("archive.zip")) {
        File fi1 = new File("alice29.txt");
        File fi2 = new File("asyoulik.txt");
        try (Archive archive = new Archive(new ArchiveEntrySettings(new StoreCompressionSettings()))) {
            archive.createEntry("alice29.txt", fi1);
            archive.createEntry("lcet10.txt", fi2);
            archive.save(zipFile);
        }
    } catch (IOException ex) {
        System.err.println(ex.getMessage());
    }

How To Add Files to 7Z Archives Without Compression

Similarly, when you want to keep files within 7z archive, use SevenZipStoreCompressionSetting while initializing SevenZipArchive instance. This ensures that the files are included in the archive as-is, without undergoing any compression algorithms. This approach is particularly beneficial for Java developers who prioritize quick access to individual files, as it eliminates the need for decompression before using the files.
Note: This code example is functional with Aspose.ZIP for Java version 24.4 and above

    try (FileOutputStream szFile = new FileOutputStream("archive.7z")) {
        File fi1 = new File("alice29.txt");
        File fi2 = new File("asyoulik.txt");
        try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipStoreCompressionSettings()))) {
            archive.createEntry("alice29.txt", fi1);
            archive.createEntry("lcet10.txt", fi2);
            archive.save(szFile);
        }
    } catch (IOException ex) {
        System.err.println(ex.getMessage());
    }

Efficiently Store Uncompressed Files in TAR Archives

The ZIP and 7z formats, renowned for compression, albeit with the ability for uncompressed storage. Conversely, there exist formats specifically conceived for initial storage purposes. CPIO and Tar, both pivotal in the early history of Unix-based operating systems, emerged in the 1970s as fundamental tools for archiving and managing files.
Unlike compressed archive formats like ZIP, the primary purpose of tar is to combine multiple files and directories into a single archive file without compression. Use TarArchive instance without any settings for composition
Sample:

    try (FileOutputStream tarFile = new FileOutputStream("joint.tar")) {
        File fi1 = new File("text.txt");
        File fi2 = new File("picture.png");
        try (TarArchive archive = new TarArchive()) {
            archive.createEntry("text.txt", fi1);
            archive.createEntry("picture.png", fi2);
            archive.save(tarFile);
        }
    } catch (IOException ex) {
        System.err.println(ex.getMessage());
    }

example-2-1: 7zip-compress-folder-recursively example-2-2: 7zip-compress-folder-recursively-2 example-3-1: tar-compress-folder-recursively example-3-2: tar-compress-folder-recursively-2

Other Supported Aspose.ZIP for Java API Features

With the Aspose.ZIP library in Java, you can seamlessly handle various tasks related to ZIP file documents. Whether you need to convert formats, merge files, edit contents, or extract data, Aspose.ZIP provides comprehensive functionality to streamline your workflow and enhance productivity.

  

Support and Learning Resources

  
  

Aspose.Zip offers individual archive processing APIs for other popular development environments, listed below: