THIS IS A SIMPLE CODE TO cREATE A ZIP FILE ........
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
FileInputStream inStream = new FileInputStream("test.txt");
ZipOutputStream outStream = new ZipOutputStream(new
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
FileInputStream inStream = new FileInputStream("test.txt");
ZipOutputStream outStream = new ZipOutputStream(new
FileOutputStream("compressed.zip"));
outStream.putNextEntry(new ZipEntry("test.txt"));
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, bytesRead);
}
outStream.closeEntry();
outStream.close();
inStream.close();
}
}
outStream.putNextEntry(new ZipEntry("test.txt"));
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, bytesRead);
}
outStream.closeEntry();
outStream.close();
inStream.close();
}
}
0 comments:
Post a Comment