-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZIP_IMGS.java
36 lines (30 loc) · 1.15 KB
/
ZIP_IMGS.java
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
34
35
36
package face;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZIP_IMGS {
public static void main(String[] args) throws IOException {
List<String> srcFiles = Arrays.asList("C:/python_ML/face_recon/finn_1.jpg", "C:/python_ML/face_recon/finn_2.jpg");
FileOutputStream fos = new FileOutputStream("C:/python_ML/face_recon/multiCompressed.zip");
ZipOutputStream zipOut = new ZipOutputStream(fos);
for (String srcFile : srcFiles) {
File fileToZip = new File(srcFile);
FileInputStream fis = new FileInputStream(fileToZip);
ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
zipOut.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
fis.close();
}
zipOut.close();
fos.close();
}//end main
}//end class