How to uncompress a file in the gzip format?
This example decompresses a gzip compressed file with java.util.zip.GZIPInputStream.
public static boolean Uncompression(String infname, String outfname){
GZIPInputStream in = null;
OutputStream out = null;
try {
in = new GZIPInputStream(new FileInputStream(infname));
out = new FileOutputStream(outfname);
byte[] buf = new byte[65536];
int len;
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
}
in.close();
out.close();
return true;
} catch (IOException e) {
if ( in != null ) {
try {
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if ( out != null ) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
return false;
}
}
Most Recent java Faqs
- How to uncompress a file in the gzip format?
- How to make a gzip file in Java?
- How to use Java String.split method to split a string by dot?
- How to validate URL in Java?
- How to schedule a job in Java?
- How to return the content in the correct encoding from a servlet?
- What is the difference between JDK and JRE?
Most Viewed java Faqs
- How to read input from console (keyboard) in Java?
- How to Retrieve Multiple Result Sets from a Stored Procedure in JDBC?
- How to Use Updatable ResultSet in JDBC?
- What are class variables in Java?
- What are local variables in Java?
- How to Use JDBC Java to Create Table?
- Why final variable in Enhanced for Loop does not act final?