Seleccionar página
	public void comprimirFichero(String filename) throws Exception {
		String outputFilename = filename+".zip";
		File outputFile = new File(outputFilename);
		FileOutputStream fos = new FileOutputStream(outputFile); 
		File inputFile = new File(filename);
		BufferedInputStream fis =  new BufferedInputStream(new FileInputStream(inputFile)); 

		ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos));
		try {

			byte[] buffer = new byte[1024];
			ByteArrayOutputStream stream = new ByteArrayOutputStream();
			int len1 = 0;
			while ((len1 = fis.read(buffer)) != -1) {
				stream.write(buffer, 0, len1);
			}				        

			byte[] bytes = stream.toByteArray();
			ZipEntry entry = new ZipEntry(outputFilename);
			zos.putNextEntry(entry);
			zos.write(bytes);
			zos.closeEntry();
		} finally {
			zos.close();
			fos.close();
			fis.close();
		}

          return outputFilename;
      }
Share