Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.*;

import java.util.zip.GZIPOutputStream;

public class Main {
    private static int BUFFER_LEN = 1024000;

    public static void toTargz(String srcFile, String targetFile) throws IOException {
        File sourceFile = new File(srcFile);
        File target = new File(targetFile);
        FileInputStream in = null;
        GZIPOutputStream gout = null;
        try {
            in = new FileInputStream(sourceFile);
            gout = new GZIPOutputStream(new FileOutputStream(target));
            byte[] array = new byte[BUFFER_LEN];
            int number = -1;
            while ((number = in.read(array, 0, array.length)) != -1) {
                gout.write(array, 0, number);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (gout != null) {
                try {
                    gout.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}