Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5850425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:08:19+00:00 2026-05-22T13:08:19+00:00

I am trying to zip a long string into a file and to retrieve

  • 0

I am trying to zip a long string into a file and to retrieve it.

The following code does not work. What it retrieves is gibberish.

public static void main(String args[]) {

    try {

        // Creating base for data
        StringBuilder sbb = new StringBuilder();
        for (int i=0;i<1000;i++)
            sbb.append("ùertyty!|").append(Integer.toString(i));

        File FileAll = new File(".\\All.data");
        FileAll.createNewFile();

        // Zipping into file
        DeflaterOutputStream g = new DeflaterOutputStream(
                new FileOutputStream(FileAll));

        OutputStreamWriter osw = new OutputStreamWriter(g);

        String base = sbb.toString();
        osw.write(base);
        osw.close();

        FileInputStream ALL_FIS = new FileInputStream(FileAll);

        // Re-reading from file
        DeflaterInputStream dis = new DeflaterInputStream(ALL_FIS);
        InputStreamReader isr = new InputStreamReader(dis);

        StringBuilder sb = new StringBuilder();
        char[] c = new char[1000];

        int count = isr.read(c);

        while ( count != -1 ) {
            sb.append(c, 0, count);
            count = isr.read(c);
        }

        isr.close();

        String retr = sb.toString();
        System.out.println("Are equal: " + retr.equals(base));
        System.out.println("Base: " + base);
        System.out.println("Retr: " + retr);

    } catch (IOException e) {

        System.err.println(e.toString());

    }

}

What am I doing wrong?

P.S.: It seems like DeflaterInputStream does not do its job and returns the content of the file as is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T13:08:20+00:00Added an answer on May 22, 2026 at 1:08 pm

    You need to use a InflaterInputStream (which decompresses) instead of a DeflaterInputStream

    http://download.oracle.com/javase/1.5.0/docs/api/java/util/zip/InflaterInputStream.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an iOS application, and trying to zip the file I have
I'm trying to create a Zip file from .Net that can be read from
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy
I am trying to write a Java class to extract a large zip file
I'm trying to download and extract a zip file in C#, specifically DotNetZip. When
I'm trying to find an zip compression and encryption component with encryption suitable for
I'm trying to use SharpZipLib to pull specified files from a zip archive. All
I am actually trying to start a process for winzip and zip a folder.
I'm trying to zip files using the command-line utility through NSTask. pseudocode: controller: init:
I am trying to unzip an archive (test.zip) containing a subfolder with some png

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.