ตัวอย่าง Gzip
ในตัวอย่างจะทำการคลายไฟล์ Gzip "C:\\users\\nopphanan7\\MyGZFile.gz" ให้ไปเป็น "C:\\users\\nopphanan7\\photo.jpg".
package demo.compress; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; public class DecompressGZipFileExample { private static final String INPUT_GZIP_FILE = "C:\\users\\nopphanan7\\MyGZFile.gz"; private static final String OUTPUT_FILE = "C:\\users\\nopphanan7\\photo.jpg"; public static void main(String[] args) { DecompressGZipFileExample gZip = new DecompressGZipFileExample(); gZip.gunzipIt(); } /** * GunZip it */ public void gunzipIt() { byte[] buffer = new byte[1024]; try { GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(INPUT_GZIP_FILE)); FileOutputStream out = new FileOutputStream(OUTPUT_FILE); int len; while ((len = gzis.read(buffer)) > 0) { out.write(buffer, 0, len); } gzis.close(); out.close(); System.out.println("Decompress file with GZip is Done"); } catch (IOException ex) { ex.printStackTrace(); } } }ผลลัพธ์ที่ได้คือ
Decompress file with GZip is Done
0 comments:
Post a Comment