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;
}
4

1 回答 1

0

您在代码中无能为力。此外,大部分时间都花在实际执行 zip 上。

因此,即使您将花费在您的部分上的时间减少到 0,总体收益也将非常小。

于 2013-08-31T06:38:21.050 回答