Simple codeNishanth Thomas December 1, 2011 at 11:50 AM
import java.io.*;
import java.util.zip.*;
public class ZipCreateExample{
/**
* @param args the command line arguments
* @throws FileNotFoundException
*/
public static void main(String[] args) throws Exception {
// input file
FileInputStream in = new FileInputStream("F:/Documents and Settings/nishanth1125/Desktop/ZipCreateExample.java");;
// out put file
ZipOutputStream out = new ZipOutputStream(new FileOutputStream("F:/Documents and Settings/nishanth1125/Desktop/tmp.zip"));
// name of file
out.putNextEntry(new ZipEntry("zippedjava.java"));
byte[] b = new byte[1024];
int count;
while ((count = in.read(b)) > 0) {
System.out.println();
// write file in zip
out.write(b, 0, count);
}
out.close();
in.close();
}
}
Instead of zipping a file, i want to zip a folder present on some location on my p.c (i.e D:\\java\pics)
Is it possible? Any code-snippet will highly be appreciated.
java ioamol June 12, 2011 at 5:24 PM
please explain java io
unknownshawn June 27, 2011 at 8:49 AM
hi hope it works
Simple codeNishanth Thomas December 1, 2011 at 11:50 AM
import java.io.*; import java.util.zip.*; public class ZipCreateExample{ /** * @param args the command line arguments * @throws FileNotFoundException */ public static void main(String[] args) throws Exception { // input file FileInputStream in = new FileInputStream("F:/Documents and Settings/nishanth1125/Desktop/ZipCreateExample.java");; // out put file ZipOutputStream out = new ZipOutputStream(new FileOutputStream("F:/Documents and Settings/nishanth1125/Desktop/tmp.zip")); // name of file out.putNextEntry(new ZipEntry("zippedjava.java")); byte[] b = new byte[1024]; int count; while ((count = in.read(b)) > 0) { System.out.println(); // write file in zip out.write(b, 0, count); } out.close(); in.close(); } }
Zipping a Filemohit July 17, 2012 at 1:43 PM
Instead of zipping a file, i want to zip a folder present on some location on my p.c (i.e D:\\java\pics) Is it possible? Any code-snippet will highly be appreciated.
Post your Comment