is there an existing FileInputStream delete on close?

前端 未结 4 979
夕颜
夕颜 2020-12-15 16:52

Is there an existing way to have a FileInputStream delete the underlying file automatically when closed?

I was planning to make my own utility class t

4条回答
  •  星月不相逢
    2020-12-15 17:51

    Can you can use File.deleteOnExit() before opening the file ?

    EDIT: On you can subclass a FileInputStream that will delete the file on 'close()';

    class MyFileInputStream extends FileInputStream
    {
    File file;
    MyFileInputStream(File file) { super(file); this.file=file;}
    public void close() { super.close(); file.delete();}
    }
    

提交回复
热议问题