Java by API/java.util.zip/DeflaterOutputStream

Материал из Java эксперт
Версия от 14:22, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

DeflaterOutputStream: close()

 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;
public class Main {
  public static void main(String[] args) {
    for (int i = 0; i < args.length; i++) {
      try {
        FileInputStream fin = new FileInputStream(args[i]);
        FileOutputStream fout = new FileOutputStream(args[i] + "dfl");
        DeflaterOutputStream dos = new DeflaterOutputStream(fout);
        for (int c = fin.read(); c != -1; c = fin.read()) {
          dos.write(c);
        }
        dos.close();
        fin.close();
      } catch (IOException ex) {
        System.err.println(ex);
      }
    }
  }
}





DeflaterOutputStream: write(int b)

 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;
public class Main {
  public static void main(String[] args) {
    for (int i = 0; i < args.length; i++) {
      try {
        FileInputStream fin = new FileInputStream(args[i]);
        FileOutputStream fout = new FileOutputStream(args[i] + "dfl");
        DeflaterOutputStream dos = new DeflaterOutputStream(fout);
        for (int c = fin.read(); c != -1; c = fin.read()) {
          dos.write(c);
        }
        dos.close();
        fin.close();
      } catch (IOException ex) {
        System.err.println(ex);
      }
    }
  }
}





new DeflaterOutputStream(OutputStream out)

 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;
public class Main {
  public static void main(String[] args) {
    for (int i = 0; i < args.length; i++) {
      try {
        FileInputStream fin = new FileInputStream(args[i]);
        FileOutputStream fout = new FileOutputStream(args[i] + "dfl");
        DeflaterOutputStream dos = new DeflaterOutputStream(fout);
        for (int c = fin.read(); c != -1; c = fin.read()) {
          dos.write(c);
        }
        dos.close();
        fin.close();
      } catch (IOException ex) {
        System.err.println(ex);
      }
    }
  }
}