Last active
August 29, 2015 14:04
-
-
Save cstrap/a38d238e630fa243f176 to your computer and use it in GitHub Desktop.
Gzip file in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void gzipFile(String source, String destination, boolean delete) { | |
try { | |
FileInputStream fis = new FileInputStream(source); | |
FileOutputStream fos = new FileOutputStream(format("%s.gz", destination)); | |
GZIPOutputStream gzipOS = new GZIPOutputStream(fos); | |
byte[] buffer = new byte[1024]; | |
int len; | |
while ((len = fis.read(buffer)) != -1) { | |
gzipOS.write(buffer, 0, len); | |
} | |
gzipOS.close(); | |
fos.close(); | |
fis.close(); | |
if (delete) { | |
new File(source).delete(); | |
} | |
} catch (IOException e) { | |
err.println(e.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment