We have already create zip file in java, lets check it with GZip

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private String OUTPUT_FILE = "/home/user/fileArchive.gz";
private String INPUT_FILE = "/home/user/fileText.txt";
 
byte[] buffer = new byte[1024];
try{
GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(new FileOutputStream(OUTPUT_FILE));
 
FileInputStream fileInputStream = new FileInputStream(INPUT_FILE);
int len;
while ((len = fileInputStream.read(buffer)) > 0) {
gZIPOutputStream.write(buffer, 0, len);
}
fileInputStream.close();
gZIPOutputStream.finish();
gZIPOutputStream.close();

}catch(IOException ex){
 ex.printStackTrace();  
}