Compressing or Zipping a file using Java program

This example demonstrates how to compress or zip a file using your Java Program.

import java.io.*;

import java.util.zip.*;

class W{
    public static void main(String[] args) throws Exception{
        int schunk=8192;
        
        FileOutputStream fos=new FileOutputStream(args[1]);
        GZIPOutputStream z=new GZIPOutputStream(fos);
        
        byte[] buffer=new byte[schunk];
        
        FileInputStream fis=new FileInputStream(args[0]);
        
        int length;
        while((length=fis.read(buffer, 0, schunk))!=-1){
            z.write(buffer, 0, length);
        }
            fis.close();
            z.close();
            fos.close();
    
    }
}
class R{
public static void main(String[] args) throws Exception{
    BufferedReader br=new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(args[0]))));
    String s;
    while((s=br.readLine())!=null){
        System.out.println(s);
    }
}
}