Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I programmatically uncompress a file that has been compressed using GZIP?

0
Posted

How can I programmatically uncompress a file that has been compressed using GZIP?

0

Location: http://www.jguru.com/faq/view.jsp?EID=228417 Created: Oct 13, 2000 Modified: 2001-08-18 18:26:26.545 Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) The java.util.zip package has classes which let you do this. Here is a program using these classes that will GZIP-uncompress a file: import java.io.*; import java.util.zip.*; public class gunzip { public static void main(String[] args) { try { if (args.length != 1) { System.out.println(“Usage: java gunzip “); System.exit(1); } String filename = null; if (args[0].endsWith(“.gz”)) { filename = args[0].substring(0, args[0].lastIndexOf(“.gz”)); } else { System.out.println(“Inputfile must have extension .gz”); System.exit(1); } FileOutputStream out = new FileOutputStream(filename); System.out.println(“Extracting archive ” + args[0]); System.out.println(“”); FileInputStream file = new FileInputStream(args[0]); GZIPInputStream in = new GZIPInputStream(file); byte[] data = new byte[2048]; int len; while ((len

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123