ZipOutputStream ZipEntry 压缩

阅读更多
import java.io.*;
import java.util.zip.*;

public class Text1 {
	public static void doit(String filein, String fileout) {
		FileInputStream fis = null;
		FileOutputStream fos = null;
		try {
			fis = new FileInputStream(filein);
			fos = new FileOutputStream(fileout);
			ZipOutputStream zos = new ZipOutputStream(fos);
			ZipEntry ze = new ZipEntry(filein);
			zos.putNextEntry(ze);
			final int BUFSIZ = 4096;
			byte inbuf[] = new byte[BUFSIZ];
			int n;
			while((n = fis.read(inbuf)) != -1) {
				zos.write(inbuf, 0, n);
			}
			fis.close();
			fis = null;
			zos.close();
			fos = null;
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(fis != null) fis.close();
				if(fos != null) fos.close();
			} catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) {
		doit("Test.java", "ssssssssssss.rar");
	}
}

 

你可能感兴趣的:(ZipOutputStream,ZipEntry,Java,压缩)