java压缩单个文件

public static void main(String[] args) throws Exception {
		File file= new File("d:"+File.separator+"1.txt");
		File zipFile = new File("d:"+File.separator+"1.zip");
		InputStream input = new FileInputStream(file);
		ZipOutputStream zipOut=null;
		zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
		zipOut.putNextEntry(new ZipEntry(file.getName()));
		zipOut.setComment("www.baidu.com");
		int temp=0;
		while((temp=input.read())!=-1){
			zipOut.write(temp);
		}
		input.close();
		zipOut.close();

		
	}

你可能感兴趣的:(java压缩单个文件)