聊聊FileOutputStream文件输入流的二三事

客官,小板凳坐好,开始啦!
在这里插入图片描述
FileOutputStream类继承了OutputStream类,OutputStream类实现了Closeable, Flushable两个接口,在FileInputStream这一章节时候,我们已经介绍过了Closeable接口,在这里就不多言语了。那Flushable这个接口的作用呢?聊聊。

/**
 * @since 1.5
 */
public interface Flushable {
   

    /**
     * 将缓冲区的数据刷新写入
     */
    void flush() throws IOException;
}

其实,就是将缓冲区的流数据写入操作。

但是,注意这个方法被OutputStream重写:

public void flush() throws IOException {
   
}

OutputStream什么都没做!而FileOutputStream类继承了OutputStream类,并没有重写该方法;所以,也就没有刷新的功能,就是个摆设。其实是供其他流使用的,比如BufferedOutputStream类:

public synchronized void flush() throws IOException {
   
	flushBuffer();
	out.flush();
}

了解了flush()方法以后,我们就探讨一下FileOutputStream类的构造方法吧!

其实,FileOutputStream类的构造方法和FileInputStream很像,只是多了一个参数FileOutputStream(String name, boolean append)第二个参数,意思是追加的意思哦!(如果不填第二个参数,默认是false

public FileOutputStream(String name) throws FileNotFoundException {
   
	this(name != null ? 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值