最开始 使用的是传统的方式, 使用的 是 InputStream 里面的 read
使用Input Strem 进行读取, 花了121 s
//use InputStream to zip file in 121s file size is 3.19MB * 10
void zipFile() {
long begin = System.currentTimeMillis();
File file = new File(zipFile);
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(file))) {
for (int i = 0; i < 10; i++) {
System.out.println("compress at " + i + " time");
try (InputStream inputStream = new FileInputStream(JPG_FILE)) {
zip.putNextEntry(new ZipEntry("FILE_NAME" + i));
int temp = 0;
while ((temp = inputStream.read()) != -1) {
zip.write(temp);
}
}
}
System.out.println("consumer time is " + (System.currentTimeMillis() - begin));
} catch (Exceptio