Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;

public class Main {
    public static void main(String[] args) throws IOException {
        Deflater def = new Deflater();
        byte[] input = new byte[1024];
        byte[] output = new byte[1024];

        FileInputStream fin = new FileInputStream("a.dat");
        FileOutputStream fout = new FileOutputStream("b.dat");

        int numRead = fin.read(input);

        def.setInput(input, 0, numRead);

        while (!def.needsInput()) {
            int numCompressedBytes = def.deflate(output, 0, output.length);
            if (numCompressedBytes > 0) {
                fout.write(output, 0, numCompressedBytes);
            }
        }
        def.finish();
        fin.close();
        fout.flush();
        fout.close();
        def.reset();
    }
}