public static void createZip(String filename,String zipfilename) { try { byte[] buf = new byte[1024]; FileInputStream fis = new FileInputStream(filename); fis.read(buf,0,buf.length); CRC32 crc = new CRC32(); ZipOutputStream s = new ZipOutputStream( (OutputStream)new FileOutputStream(zipfilename)); s.setLevel(6); ZipEntry entry = new ZipEntry(filename); entry.setSize((long)buf.length); crc.reset(); crc.update(buf); entry.setCrc( crc.getValue()); s.putNextEntry(entry); s.write(buf, 0, buf.length); s.finish(); s.close(); } catch (Exception e) { e.printStackTrace(); } }
A java blog with a collection of examples and tutorials on Java and related technologies. (Under maintenance with continuous updates) Be in touch with java jazzle or k2java.blogspot.com.
Monday, March 21, 2011
How to create a zip file with java.util.zip package
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment