0
我已经开发了一种压缩文件的方法,该文件将文件路径和文件名作为参数,并将压缩文件,如下所示,请你告诉我如何修改此方法以提高效率并且更快,因为我是优化的忠实粉丝。使压缩过程更优化一个
public File generateZipForAFile(String folderPath, String reportFileName)
throws FileNotFoundException, IOException {
File inputFile = new File(folderPath + reportFileName);
FileInputStream in = new FileInputStream(inputFile);
File outputZipFile = new File(folderPath, reportFileName + ".zip");
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputZipFile));
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(reportFileName));
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
out.close();
in.close();
return outputZipFile;
}
将您的字节缓冲区更改为大小为8192。 –
@SotiriosDelimanolis YEAH,但请告诉我这样做的好处,如果我将它的大小设置为8192 –
如果您每次阅读更多内容,您将减少IO OS调用磁盘的次数。 –