Java by API/java.util.zip/GZIPInputStream — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 17:43, 31 мая 2010

GZIPInputStream: read(byte[] buf, int off, int len)

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.GZIPInputStream;
public class MainClass {
  public static int sChunk = 8192;
  public static void main(String[] args) throws Exception {
    String zipname = "data.txt.gz";
    String source = "data.txt.gz";
    GZIPInputStream zipin;
    FileInputStream in = new FileInputStream(zipname);
    zipin = new GZIPInputStream(in);
    byte[] buffer = new byte[sChunk];
    // decompress the file
    FileOutputStream out = new FileOutputStream(source);
    int length;
    while ((length = zipin.read(buffer, 0, sChunk)) != -1)
      out.write(buffer, 0, length);
    out.close();
    zipin.close();
  }
}





new GZIPInputStream(InputStream in)

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.GZIPInputStream;
public class MainClass {
  public static int sChunk = 8192;
  public static void main(String[] args) throws Exception {
    String zipname = "data.txt.gz";
    String source = "data.txt.gz";
    GZIPInputStream zipin;
    FileInputStream in = new FileInputStream(zipname);
    zipin = new GZIPInputStream(in);
    byte[] buffer = new byte[sChunk];
    // decompress the file
    FileOutputStream out = new FileOutputStream(source);
    int length;
    while ((length = zipin.read(buffer, 0, sChunk)) != -1)
      out.write(buffer, 0, length);
    out.close();
    zipin.close();
  }
}