compress To File - Java File Path IO

Java examples for File Path IO:Zip File

Description

compress To File

Demo Code


//package com.java2s;
import java.io.*;
import java.util.zip.GZIPOutputStream;

public class Main {
    public static void compressToFile(File dest, String str)
            throws IOException {
        if (str == null) {
            return;
        }//from  ww  w  . ja v a  2s .  c  o m

        GZIPOutputStream zipOut = null;

        try {
            zipOut = new GZIPOutputStream(new FileOutputStream(dest));
            zipOut.write(str.getBytes());
        } finally {
            if (zipOut != null) {
                try {
                    zipOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related Tutorials