-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathCompressToZip.java
More file actions
33 lines (30 loc) · 1.02 KB
/
CompressToZip.java
File metadata and controls
33 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipOutputStream;
import java.util.zip.ZipEntry;
public class CompressToZip {
public static void main(String[] args) {
ContohZip1 zipObj = new ContohZip1();
zipObj.zipMyFile();
}
public void zipMyFile() {
byte[] buffer = new byte[1024];
try {
ZipOutputStream gos = new ZipOutputStream(new FileOutputStream("Your Spesific Path"));
FileInputStream fis = new FileInputStream("Your Spesific Path");
ZipEntry ze = new ZipEntry("items spesitic path to be zipped");
gos.putNextEntry(ze);
int length;
while ((length = fis.read(buffer)) > 0) {
gos.write(buffer, 0, length);
}
fis.close();
gos.finish();
gos.close();
System.out.println("File Compressed!!");
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}