/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package FileComp;
import java.io.*;
import java.util.zip.*;
public class Compress {
public static void compress(File source, File destination) throws IOException
{
byte[] buffer = new byte[1024];
FileInputStream fs = new FileInputStream(source);
FileOutputStream fo = new FileOutputStream(destination);
GZIPOutputStream gz = new GZIPOutputStream(fo);
int read;
while((read = fs.read(buffer)) != -1)
{
gz.write(buffer, 0, read);
}
gz.finish();
gz.close();
fo.close();
fs.close();
}
public static void main(String[] args)
{
File source = new File("C:\\Users\\MASTER\\Desktop\\z.txt");
File destination = new File("C:\\Users\\MASTER\\Desktop\\oCompress.txt");
try
{
compress(source, destination);
}
catch(IOException e)
{
System.out.println(e);
}
}
}