java 檔案壓縮

oxoxooxx發表於2012-03-13

java中提供了與壓縮解壓縮相關的類java.util.zip,包含如下資料流:
public class DeflaterOuputStream extends FilterOutpuStream
public class InflaterInputStream extends FilterInputStream
public class GZIPOutputStream extends FilterOutputStream
public class GZIPInputStream extends FilterInputStream
public class ZipOutputStream extends FilterOutputStream
public class ZipInputStream extends FilterInputStream
使用GZIP和ZIP處理壓縮的例項如下:

GZIPInputStream,可以使用read(),skip(),available() 方法從gzin 中讀取解壓資料。
=========

FileInputStream fin = new FileInputStream("filein.gz");
GZIPInputStream gzin = new GZIPInputStream(fin);
FileOutputStream fout = new FileOutputStream("fileout.txt");


ZipOutputStream,使用ZipEntry物件對zip檔案中每個檔案進行維護。
=========
FileInputStream fin = new FileInputStream("filein.zip");
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
FileOutputStream fout = new FileOutputStream(ze.getName());
}

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23937368/viewspace-1057579/,如需轉載,請註明出處,否則將追究法律責任。

相關文章