java - 对文件进行压缩打包后,源文件不能删除

显示正在占用

本来以为是哪个读写流忘了close,结果都检查后也没发现。

解决:除了关闭读写流,还要清除gc...

finally {
            try {
                zipOutputStream.closeEntry();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                zipOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.gc();//否则源文件删除时可能有问题
        }

 

posted @ 2020-11-17 10:59  不咬人的兔子  阅读(532)  评论(0编辑  收藏  举报