This is a discussion on How to create a ZIP File in Java? within the Java Programming forums, part of the Software Development category; How to create a ZIP File in Java?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| // these are the files to include in the ZIP file String[] source = new String[]{"source1", "source2"}; // Create a buffer for reading the files byte[] buf = new byte[1024]; try { // Create the ZIP file String target = "target.zip"; ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target)); // Compress the files for (int i=0; i<source.length; i++) { FileInputStream in = new FileInputStream(source[i]); // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(source[i])); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.closeEntry(); in.close(); } // Complete the ZIP file out.close(); } catch (IOException e) { } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| create log files in java? | saravanan | Java Programming | 2 | 08-06-2008 03:43 AM |
| How to create a Setup file in VS 2005 to start a installer from a installer file? | $enthil | C# Programming | 2 | 11-16-2007 03:10 AM |
| How to Create a Cab file in C#? | oxygen | C# Programming | 5 | 10-25-2007 01:13 AM |
| convert Excel file to CSV(or text) file using java | mobilegeek | Java Programming | 2 | 09-06-2007 06:42 AM |
| Is it possible to create an .ini file for CEAppMgr that will disable.. | theone | Mobile Software Development | 1 | 07-19-2007 01:00 AM |