开发者

Zip file all 24 hours

开发者 https://www.devze.com 2023-01-27 15:46 出处:网络
I\'ve got a problem with this method. It will be called each 24 hours (at 3 am) and should zip a file. The first time, it works correctly. at the second loop, the zip file only grows up to 4 mb (shoul

I've got a problem with this method. It will be called each 24 hours (at 3 am) and should zip a file. The first time, it works correctly. at the second loop, the zip file only grows up to 4 mb (should be 1,5gb). what do i wrong? (sorry for my bad english). here is the code:

 private static void zipFile(String srcfile, String desfile) throws IOException {
        FileInpu开发者_JS百科tStream in = new FileInputStream(srcfile);
        BufferedInputStream in2 = new BufferedInputStream(in);
        FileOutputStream out = new FileOutputStream(desfile);
        GZIPOutputStream zipOut = new GZIPOutputStream(out);
        BufferedOutputStream out2 = new BufferedOutputStream(zipOut);
        int chunk;
        appendLog("start zip...");
        while ((chunk = in2.read()) != -1) {
                out2.write(chunk);
        }
        out2.close();
        zipOut.close();
        out.close();
        appendLog("zipping file done: " + desfile);
}


Are the desfile and srcfile the same at each launch?

If so your code will replace the desfile with zipped data from srcfile each time it is called, not append new data into this file. In that condition, are you sure that the destination file size should have increased that much?


The streams in and in2 are not closed in this snippet. Maybe the srcfile is opened by the last run of this method and the second open on this file fails?

0

精彩评论

暂无评论...
验证码 换一张
取 消