Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a straight forward thing to do.</p> <p>Use </p> <p>1.<strong>ZipOutputStream</strong> -- This Class of java This class implements an output stream filter for writing files in the ZIP file format. Includes support for both compressed and uncompressed entries.</p> <p><strong>Offical Docs</strong></p> <p><a href="http://docs.oracle.com/javase/6/docs/api/java/util/zip/ZipOutputStream.html" rel="nofollow">http://docs.oracle.com/javase/6/docs/api/java/util/zip/ZipOutputStream.html</a></p> <p>2.<strong>ZipEntry</strong> -- This This class is used to represent a ZIP file entry.</p> <p><a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/util/zip/ZipEntry.html" rel="nofollow">http://docs.oracle.com/javase/1.5.0/docs/api/java/util/zip/ZipEntry.html</a></p> <pre><code>import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ConverToZip { public static void main(String[] args) { // Take a buffer byte[] buffer = new byte[1024]; try { // Create object of FileOutputStream FileOutputStream fos = new FileOutputStream("C:\\folder\\destination.zip."); // Get ZipOutstreamObject Object ZipOutputStream zos = new ZipOutputStream(fos); ZipEntry ze = new ZipEntry("source.dat"); zos.putNextEntry(ze); FileInputStream in = new FileInputStream("C:\\source.dat"); int len; while ((len = in .read(buffer)) &gt; 0) { zos.write(buffer, 0, len); } in .close(); zos.closeEntry(); //remember close it zos.close(); System.out.println("Done"); } catch (IOException ex) { ex.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload