How to GUnzip Files with Java
A common thing to do is to zip files. This combines multiple files into one so it is easier to transport them. It also is helpful because it compresses the files into a smaller size. One utility that is common in Unix/Linux is gzip. The following Java code shows how you would unzip files that have been gzipped. Please note that it assumes the file has a .gz extension and that it deletes the original file after unzipping the contents.
import java.util.zip.*; import java.io.*; ... public static String Unzip(String inFilePath) throws Exception { GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(inFilePath)); String outFilePath = inFilePath.replace(".gz", ""); OutputStream out = new FileOutputStream(outFilePath); byte[] buf = new byte[1024]; int len; while ((len = gzipInputStream.read(buf)) > 0) out.write(buf, 0, len); gzipInputStream.close(); out.close(); new File(inFilePath).delete(); return outFilePath; }
Note: I borrowed some of this code from here.
Yeah! Thanks for the code!