In this example we will show the method to decompress files from a GZIP file in Java.
Source Code
package com.beginner.examples;
import java.io.*;
import java.util.zip.GZIPInputStream;
public class FileOperator30Example {
public static void main(String[] args) throws IOException{
byte[] buffer = new byte[1024];
try
{
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream("example.gz"));
FileOutputStream fo = new FileOutputStream("example");
int len;
while ((len = gzis.read(buffer)) > 0)
{
fo.write(buffer, 0, len);
}
gzis.close();
fo.close();
System.out.println("Done!");
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
Output:
Done!
References
Imported packages in Java documentation: