我有一个简单的压缩器,可将文件转换为.zip。如何找出压缩速度以打印速度?
这是我的压缩机:
public class Compressor {
private static byte[] buffer = new byte[1024];
public static void compress(FileInputStream file) throws IOException {
FileOutputStream fos = new FileOutputStream("compressedFile.zip");
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry zipEntry = new ZipEntry("file.txt");
zos.putNextEntry(zipEntry);
int len;
while ((len = file.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
file.close();
zos.closeEntry();
zos.close();
System.out.println("Done");
}
}
long startTime = System.nanoTime();
compress();
long endTime = System.nanoTime();
long duration = (endTime - startTime); //divide by 1000000 to get milliseconds
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句