ZIPファイルを書く

774 ワード

public class ZipTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub

		FileOutputStream fout = new FileOutputStream("c://test.zip");
		ZipOutputStream zout = new ZipOutputStream(fout);
		BufferedOutputStream bos = new BufferedOutputStream(zout);
		ZipEntry ze = new ZipEntry("text.txt");
		FileInputStream fis = new FileInputStream("c://text.txt");
		byte[] content = new byte[fis.available()];
		fis.read(content);
		zout.putNextEntry(ze);
		bos.write(content);
		bos.flush();
		zout.closeEntry();
		zout.close();

	}

}