Search This Blog

Saturday, October 10, 2009

How to compress a file in the GZIP format

try {
// Create the GZIP output stream
String outFilename = "outfile.gzip";
GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename));
// Open the input file
String inFilename = "infilename";
FileInputStream in = new FileInputStream(inFilename);
// Transfer bytes from the input file to the GZIP output stream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
// Complete the GZIP file
out.finish();
out.close();
} catch (IOException e) {
}

No comments:

Post a Comment

Thanks for your comment, will revert as soon as we read it.

Popular Posts