Sample code for 30+ languages & platforms
Java

Unzip Text File to String

See more Zip Examples

Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkZip zip = new CkZip();

    success = zip.OpenZip("qa_data/zips/EC16100.zip");
    if (success == false) {
        System.out.println(zip.lastErrorText());
        return;
        }

    // Get the 1st file in the .zip
    CkZipEntry entry = new CkZipEntry();
    success = zip.EntryAt(0,entry);
    if (success == false) {
        System.out.println(zip.lastErrorText());
        return;
        }

    String fileContents = entry.unzipToString(0,"utf-8");
    System.out.println(fileContents);
  }
}