0

Help,when I finish download the file use Filedownload,how do I delete the file

asked 2012-12-26 02:39:40 +0800

jerrylyj gravatar image jerrylyj
12 1

when I finish download the file use Filedownload,how do I delete the file。
我使用Filedownload进行文件下载后,怎么样才能够马上把服务器上的文件删除呢?
有没有Filedownload 的下载完毕事件呢

delete flag offensive retag edit

3 Replies

Sort by » oldest newest

answered 2015-09-01 07:13:10 +0800

cvarona gravatar image cvarona
554 1 6

As long as you don't mind risking to lose the source file before you know for sure it's been successfully downloaded you can pass an input stream like this rather than the file itself:

public class DeleteOnCloseFileInputStream extends FileInputStream {

    private File _file;

    public DeleteOnCloseFileInputStream( File file ) throws FileNotFoundException {
        super( file );
        _file = file;
    }

    public File getFile() {
        return _file;
    }

    public void dismiss() throws IOException {
        _file = null;
        super.close();
    }

    @Override
    public void close() throws IOException {
        try {
            super.close();
        } finally {
            _file.delete();
            _file = null;
        }
    } }

Regards.

link publish delete flag offensive edit

answered 2015-09-06 10:01:06 +0800

Darksu gravatar image Darksu
1991 1 4

Hello jerrylyj,

I found a very interesting post related to your issue:

http://forum.zkoss.org/question/20033/how-to-delete-a-file-after-his-download/

Best Regards,

Darksu

link publish delete flag offensive edit

answered 2016-11-15 09:27:36 +0800

janfran gravatar image janfran
1

Thank you Cvarona, it works well!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-12-26 02:39:40 +0800

Seen: 92 times

Last updated: Nov 15 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More