欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java可删除文件的输入流工具类

程序员文章站 2022-06-06 12:28:15
...
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class DeleteOnCloseFileInputStream
    extends FileInputStream
{

    private final File file;

    private boolean delete = true;

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

    public void close()
        throws IOException
    {
        super.close();
       
        if (delete)
            file.delete();
    }

    public boolean isDelete()
    {
        return delete;
    }

    public void setDelete(boolean delete)
    {
        this.delete = delete;
    }

}