자바 zip 파일 읽 기 및 압축 zip 파일

자바 가 T11.zip 이라는 파일 을 읽 고 압축 을 푼 다음 T22.zip 이라는 파일 을 생 성 합 니 다.
코드 는 다음 과 같 습 니 다:
import java.io.*;
import java.util.zip.*;

public class ReadWriteZip {

	public static void main(String[] args) throws Exception {
		FileInputStream fi = new FileInputStream("/home/tom/test/T11.zip");
		ZipInputStream zi = new ZipInputStream(fi);
		FileOutputStream fo = new FileOutputStream("/home/tom/test/T22.zip");
		ZipOutputStream zo = new ZipOutputStream(fo);
		ZipEntry ze;
		while ((ze = zi.getNextEntry()) != null) {
			zo.putNextEntry(ze);
			byte[] buffer = new byte[1024];
			int len;
			while ((len = zi.read(buffer)) > 0) {
				zo.write(buffer, 0, len);
			}
		}
		zi.closeEntry();
		zo.closeEntry();
		zi.close();
		zo.close();
	}
}

좋은 웹페이지 즐겨찾기