java可删除文件的输入流工具类
程序员文章站
2022-06-06 12:29:32
...
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;
}
}
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;
}
}
上一篇: 我现在一分钟都不想看见你的脸,马上消失
下一篇: 这气话说得够66