import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Filezip {
public static void Zip(String source, String target) {
try {
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target)));
byte[] data = new byte[1000];
int count;
out.putNextEntry(new ZipEntry(target));
BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(source));
while ((count = buffer.read(data, 0, 1000)) != -1) {
out.write(data, 0, count);
}
buffer.close();
out.flush();
out.close();
System.out.println("file Zipped...");
} catch (Exception e) {
System.out.println("file not zipped...");
e.printStackTrace();
}
}
}
No comments:
Post a Comment