Uncompressing a File in the GZIP Format
Basically JDK1.4 has provided a library call java.util.zip for compressing and uncompressing gzip files.
try {
// Open the compressed file
String inFilename = “infile.gz”;
GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename));
// Open the output file
String outFilename = “outfile”;
OutputStream out = new FileOutputStream(outFilename);
// Transfer bytes from the compressed file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Close the file and stream
in.close();
out.close();
} catch (IOException e) {
}

Leave a Reply